【问题标题】:How to remove the tick from a tkinter checkbox如何从 tkinter 复选框中删除刻度
【发布时间】:2019-07-14 22:14:49
【问题描述】:

有两个复选框。当一个被打勾时,我需要另一个来删除它的勾,假设它被打勾。我该怎么做?

我尝试过延迟禁用和启用复选框,但它们会恢复到初始状态(如果已勾选,则保持勾选状态)。


from tkinter import *


def removetickwoman():
    # something to remove the tick from woman


def removetickman():
    # something to remove the tick from man


root = Tk()
chkvar1 = IntVar()
chkvar2 = IntVar()


check1 = Checkbutton(root, text="man", variable=chkvar1, command=removetickwoman)
check1.pack()
check2 = Checkbutton(root, text="woman", variable=chkvar2, command=removetickman)
check2.pack()

root.mainloop()

【问题讨论】:

    标签: python tkinter checkbox


    【解决方案1】:

    是的,不仅可以,而且tkinter 已经提出:您需要使用RadioButton 而不是CheckButton

    import tkinter as tk
    
    
    root = tk.Tk()    
    
    MODES = [("Man", "M"), ("Woman", "W")]
    v = tk.StringVar()
    v.set("M")
    
    for text, mode in MODES:
        b = tk.Radiobutton(root, text=text,
                        variable=v, value=mode)
        b.pack(anchor=tk.W)
    
    root.mainloop()
    

    【讨论】:

      猜你喜欢
      • 2016-08-30
      • 2021-12-21
      • 2019-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-02-22
      • 1970-01-01
      • 2020-12-28
      相关资源
      最近更新 更多