【发布时间】:2021-05-31 17:48:51
【问题描述】:
所以,我正在做一个项目,其中有一个登录屏幕,可以选择输入 id 和密码,但是在 GUI 中,我希望当单击“Enter”按钮时,它应该返回 id到调用 is 的函数。我的程序太长,所以我将举一个小例子来说明我的观点。
def func3():
cred = func1()
print(cred)
def func1(): #Function for creating the GUI
root = Tk()
def func2(): #Function for getting the data and comparing with data from MySQL
id = '123' #from entry widget
flag = 0
# Comparison done: flag now equals 0 or 1
if flag == 1: #When data matches
return id
btn = Button(master=root,text="Enter",command=func2) #This button should compare and return the id
btn.pack()
【问题讨论】:
-
flag是做什么的? -
@Cool Cloud 它只是用来指示 id 是否匹配,如果匹配,flag 将被赋予值 1 否则保持 0。如果 flag = 1 将打开下一个窗口或者如果flag = 0 ,“错误的凭据”将在标签的帮助下显示在窗口上。
-
@AST 应该是这样的,实际比较是在flag声明之后进行的(=0)
-
@AshmitRanjan
retun的值是没有用的,已经解释好了here -
将其赋值给一个变量并将其传递给另一个函数或使用
global varname。
标签: python function tkinter button return