【发布时间】:2023-03-31 22:52:01
【问题描述】:
假设我有一个这样的函数:
def test_function(select):
function_test(testing)
在 tkinter 中还有一个像这样的三个单选按钮:
selection = IntVar()
test1= Radiobutton(archive_buttons, text = 'Test Function', variable = selection, value = 1)
test2 = Radiobutton(archive_buttons, text = 'Test Function', variable = selection, value = 2)
test3 = Radiobutton(archive_buttons, text = 'Test Function', variable = selection, value = 3)
我正在尝试创建如下所示的函数。它试图将第一个函数中function_test(testing) 的参数中的内容更改为选项列表中的一个html 选项。
def select():
options = ['hi.html', 'hello.html', 'hey.html'}
counter = 1
global testing
for option in options:
if selection.get() == options[counter]:
testing = options[counter]
counter = counter + 1
return testing
因此,当我在 tkinter GUI 上单击如下按钮时,当在同一个 GUI 中选择了一个单选按钮时,我希望它在第一个函数中的 function_test(testing) 参数已经预先更改(结果我在我的 GUI 上选择一个单选按钮)。
extract_news_button = Button(function_buttons, text = 'Extract News', command = test_function, pady = 4)
但是,我收到此错误:
line 15, in select
return testing
NameError: name 'testing' is not defined
我怎样才能让它像我想要的那样工作?
【问题讨论】:
标签: python function for-loop if-statement tkinter