【发布时间】:2014-11-07 04:36:14
【问题描述】:
我正在使用 Python 2.7.6
我最近才开始使用 Tkinter,并且正在将命令提示符测验转变为 GUI 测验。到目前为止,除了我正在使用的单选按钮之外,我已经成功了。我可以创建一组单选按钮并在需要时提取它们的值,但我不确定在单击“下一步”按钮后如何更新单选按钮的文本和值。
这不是我的全部代码,因为它超过 800 行,但在这里我创建了单选按钮和函数def Guide(): 的淡化版本,我想在其中更新单选按钮。
假设Guide_list[Current].R1 和Guide_list[Current].V1 分别检索到正确的字符串和整数。
“当前”是我的计数器。
from Tkinter import *
app=Tk()
Current=0
R=IntVar()
R.set(None)
Resp1=Radiobutton(app, text=Guide_list[Current].R1, value=Guide_list[Current].V1,variable=R).pack(anchor=W)
Resp2=Radiobutton(app, text=Guide_list[Current].R2, value=Guide_list[Current].V2,variable=R).pack(anchor=W)
Resp3=Radiobutton(app, text=Guide_list[Current].R3, value=Guide_list[Current].V3,variable=R).pack(anchor=W)
Resp4=Radiobutton(app, text=Guide_list[Current].R4, value=Guide_list[Current].V4,variable=R).pack(anchor=W)
Resp5=Radiobutton(app, text=Guide_list[Current].R5, value=Guide_list[Current].V5,variable=R).pack(anchor=W)
Resp6=Radiobutton(app, text="N/A", value="N/A",variable=R).pack(anchor=W)
def Guide():
global Current
Current=Current+1
### Insert code to update the radio buttons ###
button2=Button(app,text="Next", width=15,command=Guide)
button2.pack(side='bottom')
app.mainloop()
【问题讨论】:
-
您好,请问您是否正在使用任何教程来学习 Tkinter?我看到很多人都在使用相同的“assignment+pack 反模式”,我正试图找出他们都是从哪里得到它的。
-
我正在使用我在 Youtube 上找到的各种教程。
标签: python-2.7 tkinter radio-button