Search code examples
pythoncheckboxtkinterstateappearance

tkk checkbutton appears when loaded up with black box in it


I create a check button / box, with the following call

x=ttk.Checkbutton(tab1,state='disabled',command = lambda j=i,x=k: fCheckButton(j,x))
x.state(['selected'])

The box appears fine and is selected, but it appears on load up, with a black box in it, which seems to have nothing to do with the state of it.

I have looked for reasons why, but can't actually find anyone with the same problem.

thanks


Solution

  • I've had a similar issue on Windows 7.

    After loading the app, one of my checkbuttons contained a filled square. But after clicking on it, it became a normal checkbutton:

    enter image description here

    In my case, it was because I had multiple checkbuttons sharing the same variable... After creating a separate Tk.IntVar() variable for each checkbutton, the problem disappeared.

    import Tkinter as Tk
    import ttk
    
    root = Tk.Tk()
    
    checkVar = Tk.IntVar()
    x = ttk.Checkbutton(root, variable=checkVar, text="check 1")
    x.pack()
    
    checkVar2 = Tk.IntVar()
    y = ttk.Checkbutton(root, variable=checkVar2, text="check 2")
    y.pack()
    
    root.mainloop()