Skip to content Skip to sidebar Skip to footer

Python Log Screen Bug

My tkinter log in screen app has a bug that is when i click the log in button it just show the error. from tkinter import * from tkinter import messagebox login_page = Tk() login

Solution 1:

The problem is because the username and the password variables are in the main block and when you run the code the entry boxes are empty(initially) which assigns '' to the variables. So to overcome that you should assign the variables inside the function, where now the values of the filled entry box is only taken.

Code:

from tkinter import *
from tkinter import messagebox


login_page = Tk()
login_page.title("login_page")
login_page.geometry("250x110")


defcheck_pass():
    username = log_name.get()
    userpass = log_pass.get()
    if username == name and userpass == password:
        messagebox.showinfo('Successfull','Login successfull')
    else:
        choice = messagebox.askretrycancel("Try again","Wrong password ")
        if choice == True:
            passelse:
            login_page.destroy()

......
# ALL THE SAME LINES OF CODE TILL

name = "admin"
password = "admin"


login_page.mainloop()

Also since your using a messagebox like askretrycancel, you can do certain action based on the choice by the user. So here I have said if the user clicks on retry, then ask them to login again, or else close the application. You can change it to whatever you like(or even remove it too.)

And also it is recommended to say login_page.mainloop(), just so that tkinter isnt confused at any later steps.

Hope your "bug" is cleared and do let me know if any errors :D

Cheers

Post a Comment for "Python Log Screen Bug"