我的tkinter界面上有两组radiobuttons:
1)平均值 - 中值...
2)每月 - 每周......
我想添加一个多选小部件组,但我希望它具有前两个组的相同方面。
我的第一个想法是创建一组radiobuttons并选择任何多选模式,但这种模式似乎不存在。 第二个想法是使用一组检查按钮并将指示器设置为False,但检查按钮上不存在此选项。我错过了什么可以解决我的问题吗? 或者还有其他可能性我尚未考虑过吗?
I have two groups of radiobuttons on my tkinter interface :
1) Average - Median Value ...
2) Monthly - Weekly ...
I would like to add a multiselection group of widgets BUT I would like it to have the same aspect of both previous groups.
The first idea I had was to create a group of radiobuttons and choose any multiselection mode but this mode seems not to exist. The second idea was to use a group of checkbuttons and set indicatoron on False but this option doesn't exist on checkbuttons.Did I miss anything which could solve my problem? Or is there any other possibility that I have not yet considered?
最满意答案
正确的选择是使用明确设计用于多个选择的检查按钮。 与您在问题中所写的内容相反,检查按钮确实包含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()
The proper choice is to use checkbuttons, which are explicitly designed for multiple selections. Contrary to what you wrote in your question, checkbuttons do indeed include an indicatoron option.
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()更多推荐
发布评论