【发布时间】:2017-01-28 19:25:37
【问题描述】:
import tkinter as tk
from tkinter import simpledialog
def get_pass():
user_password = simpledialog.askstring("Password Entry", "Enter your password here:")
return user_password
submitButton = tk.Button(content, text="Start", command=get_pass)
#now I want to work with the password that the user entered.
用户应该点击“开始”按钮。单击按钮后,会出现一个 tkinter 消息框,要求用户输入密码。用户输入他们的密码并提交。根据上面的代码,密码返回一个名为 user_password 的字符串。
问题是,我如何使用用户输入的内容?按钮不保存函数的返回值。
【问题讨论】:
-
command=无法检索到get_pass()的结果,所以使用global变量分配user_password。 -
@furas 谢谢,这是有道理的。我是初学者,如果您向我展示了如何将变量设置为全局变量以便我可以在该函数之外使用它,我将不胜感激。
-
在代码中查看我的答案和 cmets
标签: python user-interface tkinter