我的 guizero 用户名和密码脚本有什么问题?

问题描述

我正在处理一个涉及用户名和密码输入框的项目,这两个输入框都必须是某个短语,以便用户进入程序的下一阶段。目前,当按下 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])
    
text = Text(app,text="             ",2])

input_Box1 = TextBox(app,3],height=1,width=25)

text = Text(app,text="Username",4])

input_Box2 = TextBox(app,5],hide_text=True,text="Password",text="        ",6])

submit = PushButton(app,enabled=True,command=authenticate,width=6,7])

text = Text(app,text="Submit",7],text="          ",grid = [3,11])

picture = Picture(app,image="D:\python files\logtext.gif",12])


app.display()

我知道这有点乱,但非常感谢所有帮助。

解决方法

input_box1input_box2 是两个不同的 TextBox,因此它们不会直接等于文本字符串。你想要比较它们的

def authenticate():
    if input_box1.value == "a" and input_box2.value == "b":
        passed = True
        info("Welcome","Level 5 identification accepted. Welcome,Dr. Artyom.")
    else:
        info("Password","Your username or password is incorrect.")

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...