[英]Tkinter button not returning value from function
I am currently trying to create a small UI for a function that returns some value from a data frame based on the string that has been entered. 我目前正在尝试为函数创建一个小的UI,该函数根据已输入的字符串从数据框中返回一些值。 The string is split and each individual substring is looked up in my data frame using iloc.
字符串被分割,并使用iloc在我的数据框中查找每个子字符串。 The issue is, when calling this function using a button in Tkinter, nothing is being returned.
问题是,使用Tkinter中的按钮调用此函数时,未返回任何内容。 It works fine without Tkinter so I am unsure where the error is occurring.
如果没有Tkinter,它可以正常工作,所以我不确定错误发生在哪里。
master = Tk()
e1 = Entry(master)
list_of_inputs = e1.get().split()
def show_entry_fields():
i=0
while (i<len(list_of_inputs)):
return (backend.loc[backend['Keyword'] == list_of_inputs[i]])
i=i+1
Label(master, text="Enter Title").grid(row=0)
e1.grid(row=0, column=1)
Button(master, text='Show', command=show_entry_fields).grid(row=0, column=2, sticky=W, pady=4)
mainloop( )
Couple of things: 几件事情:
show_entry_fields()
function will always run once regardless of how many inputs provided, since you put a return statement inside the loop show_entry_fields()
函数中的while循环将始终运行一次,因为您在循环中放入了return语句 Possible implementation: 可能的实现:
master = Tk()
e1 = Entry(master)
def show_entry_fields():
list_of_inputs = e1.get().split()
result = []
for entry in list_of_inputs:
result.append(backend.loc[backend['Keyword']] == entry)
# Alternatively, you can create the list with
# result = [backend.loc[backend['Keyword']] == entry for entry in list_of_inputs]
# Here, deal with the result
Label(master, text="Enter Title").grid(row=0)
e1.grid(row=0, column=1)
Button(master, text='Show', command=show_entry_fields).grid(row=0, column=2, sticky=W, pady=4)
mainloop()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.