繁体   English   中英

下拉框和单选按钮

[英]Drop down boxes and radio buttons

我有一个下拉框,当选择每个值时,它会具有不同的值,它会更改每个单选按钮的值,但是我想这样做,所以当您为单选按钮选择一个选项时,它会将选择保留在下拉列表中框值,并且不会影响下拉框的其他任何值。

这对于AFL小费来说是否有帮助,因为这很难解释,并且我的代码相当长,因此有助于澄清。 我已经掌握了一些主要的代码部分,但是我可能遗漏了一些会有所帮助的内容,所以只问您是否需要更多。

variable = StringVar()

round_change = ttk.Combobox(root, state = "readonly", textvariable = variable, values = ['Round 1', 'Round 2'])

def notify (event):
    a = variable.get()
    if a == "Round 1":
        round_games(round_1)
    elif a == "Round 2":
        round_games(round_2)

round_change.bind("<<ComboboxSelected>>", notify)

def round_games(list):
    tip_1_0 = ttk.Radiobutton(root, text = list[0] + "\n" + list[1], width = 13, variable = 1, value = 1)
    tip_1_1 = ttk.Radiobutton(root, text = list[2] + "\n" + list[3], width = 13, variable = 1, value = 2)

您可以通过将组合框的状态设置为“禁用”来禁用组合框。

def click_radio():
    round_change.state(['disabled'])
    round_change.pack()

tip_1_0 = ttk.Radiobutton(root, text = list[0] + "\n" + list[1], width = 13, variable = 1, value = 1, command=click_radio)

顺便说一句要取消设置状态,您需要调用round_change.state(['!disabled'])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM