2017-06-06 49 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()方法創建複選框之後 - 看起來更好。