【发布时间】:2020-04-19 20:11:07
【问题描述】:
我有一个 tkinter gui,它有一个基本的输入框和搜索按钮。在名为 SearchList.py 的模块中搜索列表
Main.py
from tkinter import *
from SearchList import *
root = Tk()
Output = []
def search():
search = e.get()
Output= SearchList.go(search)
#search bar
e= Entry(root, width=50, borderwidth=5)
e.grid(row=0, column=0, columnspan=2)
#search button
doneButton = Button(root, text="Search", width= 10, command=search).grid(row=0, column=4)
#arranges output in a 5 column rectangle
r, c = (1,0)
c_limit= 5
for thing in Output:
myButton = Button(root, text=thing,height=5, width=25, borderwidth=3, padx=10).grid(row=r,column=c)
c+=1
if c == c_limit:
c=0
r+=1
root.mainloop()
这让我可以输入我想要搜索的内容并将其发送到 Searchlist.py 模块,并且输出(列表中的匹配项)被排列在一个矩形中。
SearchList.py
Output = []
def main(search):
for x in range(list):
if list[x]== search:
Output.append(list[x])
else:
continue
Output.sort
return Output
def go(search):
with client:
client.loop.run_until_complete(main(search))
但它不断返回None。
我也知道我一定是错误地调用了模块——只是不确定如何。
【问题讨论】:
-
您可能只是在
return client.loop.run_until_complete(main(search))中缺少return在SearchList.go中。 -
作为一个程序员,你应该非常非常非常努力地不使用全局变量。
-
@Erich 这是我的问题,但由于某种原因,列表没有显示在 tkinter 网格中?
-
您在
search的开头缺少global Output。 -
哦,我明白了。用重新格式化的代码回答,我会接受它
标签: python search module return parameter-passing