2017-06-14 83 views
0

我有我的Tkinter接口兩組單選按鈕的:多選單選按鈕/ Checkbuttons [ 「indicatoron」] = FALSE

1)平均 - 中間值...

2)月 - 每週...

Current interface

我想添加小工具的多選組,但我想它有兩個先前組的相同的方面。

  • 我的第一個想法是創建一組radiobuttons並選擇任何多選模式,但這種模式似乎不存在。
  • 第二個想法是用一組checkbuttons,併成立indicatoron上假,但該選項不上checkbuttons存在。

我錯過了任何可能解決我的問題?或者還有沒有其他的可能性,我還沒有考慮?

+0

請提供[最小,完整的,並且可驗證示例](https://stackoverflow.com/help/mcve)。這將使我們能夠協助你解決問題。 –

回答

1

正確的選擇是使用checkbuttons,這是明確設計進行多選。與您在問題中所寫的相反,checkbutton的確包含indicatoron選項。

import tkinter as tk 

root = tk.Tk() 

vars = {} 
frame = tk.Frame(root) 
frame.pack(side="top", fill="x", padx=10, pady=10) 
for color in ("red", "orange", "green", "blue", "indigo", "violet"): 
    checkbutton = tk.Checkbutton(frame, onvalue=1, offvalue=0, 
           text=color, indicatoron=False, 
           width=6) 
    checkbutton.pack(side="left", fill="x", expand=True) 

root.mainloop() 

screenshot of checkbuttons with indicatoroff set to true

+0

哦,我甚至不知道我是如何錯過它的 –