You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I made a GUI to be able to mute windows. After I created the GUI and the script to control the sound I linked the two together. When I run the script, there is an error ctypes.ArgumentError: argument 1: TypeError: wrong type, the error is in the script line volume.SetMute(boolMute, None) contained in the mute() method. Here I show the code.
import customtkinter
from customtkinter import filedialog
from ctypes import cast, POINTER
from comtypes import CLSCTX_ALL
from pycaw.pycaw import AudioUtilities, IAudioEndpointVolume, ISimpleAudioVolume
# System Setting
customtkinter.set_appearance_mode("Light")
customtkinter.set_default_color_theme("blue")
class Myapp():
devices = AudioUtilities.GetSpeakers()
interface = devices.Activate(
IAudioEndpointVolume._iid_, CLSCTX_ALL, None)
volume = cast(interface, POINTER(IAudioEndpointVolume))
def __init__(self):
self.root = customtkinter.CTk()
self.root.geometry('1050x600')
self.root.title("APx Platform")
# SOUND CONTROL
self.label1 = customtkinter.CTkLabel(self.root, text="Volume Setting", font=("Nunito",15))
self.label1.grid(row=1, column=1)
self.toggleBtn = customtkinter.CTkButton(self.root, border_width=2.5, border_color="red", text_color="red" , text="Mute Off", font=("Ubuntu", 12), command=self.mute)
self.toggleBtn.grid(row=2, column=3)
self.var = IntVar()
self.var(getCurrentMasterVolume())
self.scale = customtkinter.CTkSlider(self.root, from_=0, to=100, variable=self.var, command=self.setMasterVolume, orientation="horizontal", button_corner_radius=3, button_length=20)
self.scale.grid(row=1, column=1)
def getCurrentMasterVolume(self):
return int(round(volume.GetMasterVolumeLevelScalar() * 100))
def displayCurrentVolume(self):
selection = str(getCurrentMasterVolume()) + "%"
label.config(text = selection)
def setMasterVolume(self):
scalarVolume = int(var.get()) / 100
volume.SetMasterVolumeLevelScalar(scalarVolume, None)
displayCurrentVolume()
def mute(boolMute):
sessions = AudioUtilities.GetAllSessions()
for session in sessions:
volume = session._ctl.QueryInterface(ISimpleAudioVolume)
print("volume.GetMute(): %s" % volume.GetMute())
volume.SetMute(boolMute, None)
def toggle():
'''
use
t_btn.config('text')[-1]
to get the present state of the toggle button
'''
if toggleBtn.configure('text')[-1] == 'Mute Off':
toggleBtn.configure(text='Mute On')
mute(1)
else:
toggleBtn.configure(text='Mute Off')
mute(0)
app = Myapp()
app.root.mainloop()
When clicked on the button, an error appears as explained above. Can you please fix it as I need this for a project.
Thank You.
The text was updated successfully, but these errors were encountered:
I made a GUI to be able to mute windows. After I created the GUI and the script to control the sound I linked the two together. When I run the script, there is an error
ctypes.ArgumentError: argument 1: TypeError: wrong type
, the error is in the script linevolume.SetMute(boolMute, None)
contained in the mute() method. Here I show the code.When clicked on the button, an error appears as explained above. Can you please fix it as I need this for a project.
Thank You.
The text was updated successfully, but these errors were encountered: