Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ctypes.ArgumentError: argument 1: TypeError: wrong type #75

Open
mhd-fauzan opened this issue May 1, 2023 · 0 comments
Open

ctypes.ArgumentError: argument 1: TypeError: wrong type #75

mhd-fauzan opened this issue May 1, 2023 · 0 comments

Comments

@mhd-fauzan
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant