Python 2.7 你能更新tkinter中单选按钮的文本和值吗?

Python 2.7 你能更新tkinter中单选按钮的文本和值吗?,python-2.7,tkinter,radio-button,Python 2.7,Tkinter,Radio Button,我正在使用Python 2.7.6 我最近刚开始使用Tkinter,我正在将命令提示符测试转换为GUI测试。到目前为止,除了我正在使用的单选按钮外,我一直都很成功。我可以创建一组单选按钮,并在需要时提取它们的值,但我不确定如果可能,在单击“下一步”按钮后如何更新单选按钮的文本和值 这不是我的全部代码,因为它超过800行,但这里是我创建单选按钮的地方,以及我想要更新单选按钮的函数def Guide():的淡化版本 假设Guide\u list[Current]。R1和Guide\u list[Cu

我正在使用Python 2.7.6

我最近刚开始使用Tkinter,我正在将命令提示符测试转换为GUI测试。到目前为止,除了我正在使用的单选按钮外,我一直都很成功。我可以创建一组单选按钮,并在需要时提取它们的值,但我不确定如果可能,在单击“下一步”按钮后如何更新单选按钮的文本和值

这不是我的全部代码,因为它超过800行,但这里是我创建单选按钮的地方,以及我想要更新单选按钮的函数
def Guide():
的淡化版本

假设
Guide\u list[Current]。R1
Guide\u 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()

您可以使用
config
方法修改小部件的属性

    def Guide():
        global Current
        Current=Current+1
        Resp1.config(text="Hello")
但是,只有当您仍然有对您试图配置的小部件的现有引用时,才能执行此操作。因为你的代码是现在,你没有这个;Resp1到Resp6都是None,因为您将它们指向了
.pack
的返回值,而不是实际的单选按钮。另见。你需要单独打包

Resp1=Radiobutton(app, text=Guide_list[Current].R1, value=Guide_list[Current].V1,variable=R)
Resp2=Radiobutton(app, text=Guide_list[Current].R2, value=Guide_list[Current].V2,variable=R)
Resp3=Radiobutton(app, text=Guide_list[Current].R3, value=Guide_list[Current].V3,variable=R)
Resp4=Radiobutton(app, text=Guide_list[Current].R4, value=Guide_list[Current].V4,variable=R)
Resp5=Radiobutton(app, text=Guide_list[Current].R5, value=Guide_list[Current].V5,variable=R)
Resp6=Radiobutton(app, text="N/A", value="N/A",variable=R)

Resp1.pack(anchor=W)
Resp2.pack(anchor=W)
Resp3.pack(anchor=W)
Resp4.pack(anchor=W)
Resp5.pack(anchor=W)
Resp6.pack(anchor=W)

嘿,我能问一下你是否正在使用任何教程来学习Tkinter吗?我看到很多人都在使用相同的“作业+包反模式”,我正试图找出他们都是从哪里得到它的。