0

I'm working on a project involving username and password input boxes that both have to be a certain phrase in order for the user to get to the next stage of the program. Currently, when the PushButton is pressed, regardless of whether the correct username and password are typed, the user will always get the "Sorry, your username or password is incorrect" infobox instead of the successful one.

My program so far is below. Please ignore the passed variable, it's important for something later, and all the blank texts are to force other widgets into the correct places.

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()

I know it's a bit of a mess, but all help is greatly appreciated.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685
  • Have you considered printing out `input_box1` to see if it's what you think it is, just before comparing it to `"a"`. – Bryan Oakley Feb 24 '21 at 02:27

1 Answers1

-1

input_box1 and input_box2 are two different TextBoxes, so they won't be equal to text strings directly. You instead want to compare their values:

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.")
dtanabe
  • 1,611
  • 9
  • 18
  • The properties of a TextBox are listed here, by the way: https://lawsie.github.io/guizero/textbox/ – dtanabe Feb 24 '21 at 01:57
  • @BryanOakley `guizero.TextBox` is not a tkinter `Text` widget. – acw1668 Feb 24 '21 at 03:04
  • @BryanOakley I believe OP is using guizero. and from the sample code it looks like `input_box1` is a `guizero.TextBox`, which _does_ have a `value` property (at least according to the documentation I linked to). – dtanabe Feb 24 '21 at 03:20
  • @dtanabe: ah, thanks for pointing that out. My mistake. – Bryan Oakley Feb 24 '21 at 03:53