How can I integrate Tkinter with Python log in screen? How can I integrate Tkinter with Python log in screen? tkinter tkinter

How can I integrate Tkinter with Python log in screen?


I extended your example. I made a class that holds your login window.

from tkinter import *import tkinter.messagebox as tmclass LoginFrame(Frame):    def __init__(self, master):        super().__init__(master)        self.label_username = Label(self, text="Username")        self.label_password = Label(self, text="Password")        self.entry_username = Entry(self)        self.entry_password = Entry(self, show="*")        self.label_username.grid(row=0, sticky=E)        self.label_password.grid(row=1, sticky=E)        self.entry_username.grid(row=0, column=1)        self.entry_password.grid(row=1, column=1)        self.checkbox = Checkbutton(self, text="Keep me logged in")        self.checkbox.grid(columnspan=2)        self.logbtn = Button(self, text="Login", command=self._login_btn_clicked)        self.logbtn.grid(columnspan=2)        self.pack()    def _login_btn_clicked(self):        # print("Clicked")        username = self.entry_username.get()        password = self.entry_password.get()        # print(username, password)        if username == "john" and password == "password":            tm.showinfo("Login info", "Welcome John")        else:            tm.showerror("Login error", "Incorrect username")root = Tk()lf = LoginFrame(root)root.mainloop()

Sorry for not going over every single line what is happening there. I leave it to you to figure out. Its good exercise. But I will say that the most important is command = self._login_btn_clicked. This function will be executed when you click login button. In this function, you take the values of username and password, and check if they are correct. Also I did not attach any callbacks to the checkbox. But it would be similar to what is already done.

Edit: Edited as requested in the comments.

Login prompt


You probably want a 'Login' button, right? If you make that, you can bind a function to run when it is clicked using button's the command argument. In the function that the button calls you can do the checks for the correct username and password. Do not use the while loops though, just check once each time the button is pressed and respond accordingly.