【发布时间】:2021-04-25 18:46:51
【问题描述】:
我正在编写一个程序,它根据用户的选择从特定文本文件中读取单词列表。
然后这个单词列表将用作另一个函数“startgame()”的参数,该函数也是我的 Tkinter 窗口的“事件”,它根据用户的选择显示从文件中获取的单词.
但是,这里的问题是,当函数是 Tkinter 事件时,只能有一个参数,因此我无法将获取的单词用作参数。
这是一个最小的可重现示例供参考 -
window = Tk()
def func1():
fh = open("file.txt")
reader = fh.read()
fetched_words = reader.split('|')
window.bind('<Return>', func2)
def func2(event): # here I need to add another parameter
word_display.configure(text=fetched_words[0]) # must have argument 'words' instead of 'fetched_words'
我已经尝试了多种方法来修复这个错误,但到目前为止都没有成功。请帮帮我!
【问题讨论】:
-
我已经编辑了我的问题并尽力解释它
标签: python function tkinter parameters arguments