#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2017
    Posts
    20
    Rep Power
    0

    [Python 3 + Tkinter] On/Off Checkbutton not works, help needed!


    Hey Python Programmers...

    I Try to create an on/off check button for winsounds, but it doesn't works.
    This is my code:

    Code:
    import winsound
    from tkinter import *
    
    main = Tk()
    
    def addButtons():
    
        def playExit():
            winsound.PlaySound('SystemExit', winsound.SND_ALIAS)
    
        def playExc():
            winsound.PlaySound('SystemExclamation', winsound.SND_ALIAS)
    
        def playTing():
            winsound.PlaySound('*', winsound.SND_ALIAS)
                
        buttonexit = Button(main, text = "Play Exit", command = playExit)
        buttonexc = Button(main, text = "Play Exc", command = playExc)
        buttonting = Button(main, text = "Play All", command = playTing)
    
        buttonexit.pack()
        buttonexc.pack()
        buttonting.pack()
    
    
    cvar = IntVar()
    
    
    checkbutton = Checkbutton(main, text = 'my Test', variable = cvar, onvalue = 1, offvalue = 0, command = addButtons)
    checkbutton.pack()
    
    if checkbutton.onvalue == 1:
        cvar.set(addButtons)
    else:
        cvar.set(0)

    If i run this script, i get an error and my buttons adding again by pressing
    the on/off button...

    Can anyone help me to correct my code, just i can expiriment with it ?...

    Thanks for correct my code, Jamie.
  2. #2
  3. Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Aug 2011
    Posts
    5,910
    Rep Power
    509
    My tkinter.Checkbutton does not have onvalue nor offvalue attributes, although they are documented when I ask for help.

    >>> import tkinter
    >>> help(tkinter.Checkbutton)

    What error do you observe?
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    May 2009
    Posts
    656
    Rep Power
    39
    You do not have Checkbuttons, these are regular Buttons that control winsound. And we can't help without knowing what the complete error message says. Also, why not use a regular button to create the other buttons also.
    Last edited by dwblas; January 9th, 2018 at 04:45 PM.

IMN logo majestic logo threadwatch logo seochat tools logo