Tkinter: is there a way to check checkboxes by default?

后端 未结 4 859
天涯浪人
天涯浪人 2020-12-10 14:43

I have this piece of code that will create a simple checkbox :

from Tkinter import *

CheckVar = IntVar()
self.checkbutton = Checkbutton(self.root, text = \"         


        
4条回答
  •  -上瘾入骨i
    2020-12-10 15:20

    I think the function you are looking for is .select()

    This function selects the checkbutton (as can be assumed from the function name)

    Try calling this function after your widget is defined:

    from Tkinter import *
    
    CheckVar = IntVar()
    self.checkbutton = Checkbutton(self.root, text = "Test", variable = CheckVar)
    self.checkbutton.select()
    

    By calling the function right after the widget is created, it looks as though it's selected by default.

提交回复
热议问题