Programmatically adjust the volume on my Windows 7 computer

坚强是说给别人听的谎言 提交于 2019-12-12 18:04:02

问题


I was wondering if it was possible to make a Tkinter scale correspond with the volume of the computer. In other words, by dragging the scale up, could the volume of the computer increase? Here is just some random code I drew up. I am running a a 64-Bit Windows 7 operating system.

1    from Tkinter import *
2
3    def sel():
4       selection = "Value = " + str(var.get())
5       label.config(text = selection)
6
7    root = Tk()
8    var = DoubleVar()
9    scale = Scale( root, variable = var )
10   scale.pack(anchor=CENTER)
11
12   button = Button(root, text="Get Scale Value", command=sel)
13   button.pack(anchor=CENTER)
14
15   label = Label(root)
16   label.pack()
17
18   root.mainloop()

Honestly I do not care if it can't be done. I was just wondering if it was possible. Thanks for all the help!


回答1:


See Changing master volume level for how to do this in C and then mix with How to use win32 API's with python. Then bind your resulting callbacks to Tkinter gui events.




回答2:


I know that this is an old question, but the top answer is out of the scope of most people's abilities. I write in python to avoid C, not to embrace it.

The realistic best answer is to install something for the command line (e.g. Nircmd) and then to use subprocess (preinstalled) to call it e.g.subprocess.getoutput("nircmd setsysvolume 0") Hope this helps anyone else who finds it.



来源:https://stackoverflow.com/questions/11769709/programmatically-adjust-the-volume-on-my-windows-7-computer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!