Looking at the documentation for pyautogui, I don't see any method called set, so set.volume is invalid. It does mention 'volumedown', 'volumemute', and 'volumeup' in the keyboard functions, which is probably what you actually want.
import tkinter as tk
import pyautogui
window = tk.Tk()
window.geometry("400x200")
def set_volume(val) -> None:
global last_scale_value # allow this function to modify last_scale_val
val = int(val) # convert val to an integer
if val < last_scale_value:
pyautogui.press('volumedown')
elif val > last_scale_value:
pyautogui.press('volumeup')
# store the latest value for comparison
last_scale_value = val
scale = tk.Scale(
window,
from_=100,
to=0,
length=150,
orient='vertical',
command=set_volume
)
scale.set(50)
scale.pack(padx=20, pady=20)
# create a variable to compare against so we know which way the volume is being adjusted
last_scale_value = int(scale.get())
window.mainloop()
One important thing to note: this is NOT directly setting your computer's volume to the current value of the scale (pyautogui can't do that as far as I can tell) - it's sending keypresses based on changes to the scale.
Your computer usually doesn't consider keyboard volume key presses as a range between 0-100, typically one keypress will change the volume by a fixed amount > 1%. Keep this in mind!
Pro Tip: you don't need both the "star import"* and the regular import statement. You can (and probably should) just do import tkinter as tk and import pyautogui.
*See here for info on why star imports are regarded as a bad idea