2017-06-06 47 views
0

减号我有一个复选框,在Mac上默认显示减号的问题:的Tkinter checkbuttons默认显示在Mac

screenshot

下面的代码被用于生产这些一个labelframe内:

for x in ["Why", "Do", "These", "Have", "Minus", "Signs", "On", "Them?", "Clicked once", "Clicked twice"]: 
    check_button = ttk.Checkbutton(
     check_button_labelframe, 
     text=x, 
    ) 
    check_button.grid(column=0, row=current_button_row, sticky="W") 
    current_button_row += 1 

什么是减号是什么意思?我希望它们被检查或空白(如分别在屏幕截图中的“点击一次”和“点击两次”)。我试着提供variable=somevariable其中

somevariable=tk.IntVar() 
somevariable.set(1) 

但是这不会改变任何东西。我在这里使用ttk .checkbuttons,当使用tk.checkbuttons时,所有的框都是空白的。

编辑:一个更完整的例子:

 cases = { 
      "case1": { 
       "description": "This is case 1", 
       "enabled_or_not": 0, 
       "enabled_var": tk.IntVar() 
      }, 
      "case2": { 
       "description": "This is case 2", 
       "enabled_or_not": 1, 
       "enabled_var": tk.IntVar() 
      } 
     } 

     for case in cases.keys(): 
      case_info = cases[case] 
      case_info["enabled_var"].set(case_info["enabled_or_not"]) 
      check_button = ttk.Checkbutton(
       check_button_labelframe, 
       text=case_info["description"], 
       variable=case_info["enabled_var"], 
       onvalue=1, 
       offvalue=0 
      ) 
      check_button.grid(column=0, row=current_button_row, sticky="W") 
      current_button_row += 1 

这将产生这样的:

Another screenshot

编辑2: 这似乎有事情做与如何Mac电脑动画复选框,检查出来:

Screen recording gif

EDIT 1000(MCVE):你说得对,伙计们,如果我夺走一切,但复选框,它的工作原理:

app = tk.Tk() 
app.wm_title("MCVE") 
app.geometry("320x240") 

# Tk checkbuttons 
first_var = tk.IntVar() 
first_var.set(1) 
first_checkbox = tk.Checkbutton(app, text="This should be enabled", variable=first_var, onvalue=1, offvalue=0) 
first_checkbox.grid(column=0, row=0, sticky="W") 

second_var = tk.IntVar() 
second_var.set(0) 
second_checkbox = tk.Checkbutton(app, text="This should be disabled", variable=second_var, onvalue=1, offvalue=0) 
second_checkbox.grid(column=0, row=1) 

# Ttk checkbuttons 
third_var = tk.IntVar() 
third_var.set(1) 
third_checkbox = ttk.Checkbutton(app, text="This should be enabled", variable=third_var, onvalue=1, offvalue=0) 
third_checkbox.grid(column=0, row=2) 

fourth_var = tk.IntVar() 
fourth_var.set(0) 
fourth_checkbox = ttk.Checkbutton(app, text="This should be disabled", variable=fourth_var, onvalue=1, offvalue=0) 
fourth_checkbox.grid(column=0, row=3) 

app.mainloop() 

It's aliiiive

所以它有与存储在字典中的变量有什么关系?

+0

你在做'somevariable = tk.IntVar()'循环内,或外循环? – Kevin

+0

@Kevin它们在循环之外定义,作为字典的成员,如果这有所作为。而在循环中,我做'ttk.CheckButton(...,变量= mydict [somevariable])' – Plasma

+0

是否使用相同的一个IntVar为checkbuttons整组,或者您使用的值为每个checkbutton不同IntVar? – Kevin

回答

0

减号是默认状态下,Windows上它与灰色的背景检查的标志。

我更喜欢使用.deselect()方法创建复选框之后 - 看起来更好。