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

后端 未结 4 860
天涯浪人
天涯浪人 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条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-10 15:15

    Your CheckVar is a local variable. It's getting garbage collected. Save it as an object attribute. Also, you can create the variable and initialize it all in one step:

    self.CheckVar = IntVar(value=1)
    self.checkbutton = Checkbutton(..., variable = self.CheckVar)
    

提交回复
热议问题