我已经编写了很多年的代码,直到现在,我总能在谷歌上找到答案。我无论如何也做不到。在
在此之前,我有几个不同国家的列表,以及十几个功能,只为用户打印内容,在这里不相关。在
我使用tkinter创建一个输入框,用户可以在其中键入国家(输入被分配给typedCountry)。然后在mainProgram()函数中的每个列表中搜索国家,每次找到匹配的列表时都返回另一个函数。一切都正常工作,除了我希望mainProgram()将信息返回到tkinter GUI框而不是终端。我已经和它斗争了好几个小时了,我找不到一个让它工作的方法,我愿意接受任何建议,即使是大幅度地修改代码或使用tkinter以外的东西也可以。在
def mainProgram():
typedCountry = e.get()
Country = typedCountry.lower()
print 'Your country is: ' + typedCountry + '\n'
if Country in bannedCountries:
banned(typedCountry)
if Country in cpBannedCountries:
cpBanned(typedCountry)
if Country in skrillBannedCountries:
skrillBanned(typedCountry)
if Country in bacsCountries:
Bacs(typedCountry)
if Country in sepaCountries:
sepa(typedCountry)
if Country in eftCountries:
eft(typedCountry)
if Country in ltdCountries:
ltd(typedCountry)
if Country in marketsCountries:
markets(typedCountry)
master = Tk()
e = Entry(master)
e.pack()
e.focus_set()
var = mainProgram()
def textBox():
root = Tk()
label = Message(root, textvariable=var)
label.pack()
root.mainloop()
b = Button(master, text = "Search", command = mainProgram)
b.pack()
mainloop()
如果你想要的话,这里是主要的代码(例如,如果你想在你的终端上运行它):
^{pr2}$
只需替换例如:
有:
^{pr2}$在你的每个功能中。在
或者最好加上:
在
e
行下,然后将return
替换为:你不能调用textBox函数。要使其正常工作,如果我正确地理解了问题,被调用的函数必须更新文本框标签。不要把函数发送给下级。代码的缩短版本
相关问题 更多 >
编程相关推荐