Tkk checkbutton appears on boot with a black box in it

I create a check button / button with the next call

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

The box displays fine and is selected, but it appears at boot time, with a black box in it that appears to have nothing to do with the state.

I have been looking for reasons, but cannot find anyone with the same problem.

thank

+4
source share
2 answers

I had a similar problem in Windows 7.

After downloading the application, one of my control buttons contained a filled square. But after clicking on it, he became the usual checkbutton:

enter image description here

, , ... Tk.IntVar() .

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()
+2

, , , , . : http://effbot.org/tkinterbook/checkbutton.htm " ".

checkbutton_text = []
checkbutton_text.append("One")
checkbutton_text.append("Two")
checkbutton_text.append("Three")
checkbutton_variable = []
checkboxes = []
jrow = 1
for index in range(len(checkbutton_text)):
   checkbutton_variable.append(IntVar())
   #checkbutton_variable[index].set(1) # initialize all on
   checkbutton_variable[index].set(0) # initialize all off
   checkboxes.append(Checkbutton(frame, text=checkbutton_text[index], variable=checkbutton_variable[index]))
   checkboxes[index].grid(row=jrow, column=0, sticky='w')
   #****************
   # adding the line below fixed checkbuttons being filled on startup
   checkboxes[index].var = checkbutton_variable[index]
   #****************
   jrow += 1
0

Source: https://habr.com/ru/post/1673237/


All Articles