Skip to content

Instantly share code, notes, and snippets.

@vigilantPotato
Created June 3, 2024 21:03
Show Gist options
  • Save vigilantPotato/ed9d95369b3bcadf97e27e8ce74d182f to your computer and use it in GitHub Desktop.
Save vigilantPotato/ed9d95369b3bcadf97e27e8ce74d182f to your computer and use it in GitHub Desktop.
Master volume setting scale for windows
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume
import ctypes
import tkinter
class MasterVolumeSettingScale(tkinter.Scale):
def __init__(self, root):
super().__init__(
root,
bg="lightblue",
command=self.set_volume,
label="Master Volume",
length=200,
orient="horizontal",
)
#get audio object and initial setting
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
self.volume = interface.QueryInterface(IAudioEndpointVolume)
current_volume = self.volume.GetMasterVolumeLevelScalar()
self.set(int(current_volume*100))
def set_volume(self, value):
self.volume.SetMasterVolumeLevelScalar(int(value)/100, None)
if __name__ == '__main__':
ctypes.windll.shcore.SetProcessDpiAwareness(1)
root = tkinter.Tk()
scale = MasterVolumeSettingScale(root)
scale.pack()
root.mainloop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment