我正在做一个涉及用户名和密码输入框的项目,这两个输入框都必须是某个短语才能让用户进入程序的下一阶段。目前,当按下 PushButton 时,无论是否输入了正确的用户名和密码,用户总是会得到“对不起,您的用户名或密码不正确”的信息框,而不是成功的信息框。
到目前为止,我的程序如下。请忽略传递的变量,这对以后的事情很重要,所有的空白文本都是为了强制其他小部件进入正确的位置。
from guizero import App, Text, TextBox, PushButton, info, Picture
passed = False
def authenticate():
if input_box1 == "a" and input_box2 == "b":
passed = True
info("Welcome", "Level 5 identification accepted. Welcome, Dr. Artyom.")
else:
info("Password", "Your username or password is incorrect.")
app = App(title="AppTest", width=900, height=600, layout="grid", bg=[255,255,255])
text = Text(app, text=" ", grid=[0,0])
text = Text(app, text=" ", grid=[1,1])
text = Text(app, text="Please enter a valid username and password.", grid=[2,1], color=[0,0,0])
text = Text(app, text=" ", grid=[2,2])
input_box1 = TextBox(app, grid=[2,3], height=1, width=25)
text = Text(app, text="Username", grid=[1,3], color=[0,0,0])
text = Text(app, text=" ", grid=[2,4])
input_box2 = TextBox(app, grid=[2,5], hide_text=True, height=1, width=25)
text = Text(app, text="Password", grid=[1,5], color=[0,0,0])
text = Text(app, text=" ", grid=[2,6])
submit = PushButton(app, enabled=True, command=authenticate, height=1, width=6, grid=[2,7])
text = Text(app, text="Submit", grid=[2,7], color=[0,0,0])
text = Text(app, text=" ", grid = [3,11])
picture = Picture(app, image="D:\python files\logtext.gif", grid=[2,12])
app.display()
我知道这有点乱,但非常感谢所有帮助。