2017-06-14 85 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

哦,我甚至不知道我是如何错过它的 –