In this tutorial, we will learn how to build a Login App GUI using Python’s Tkinter library. Tkinter is the standard GUI toolkit that comes with Python and is easy to use for creating interactive graphical user interfaces.
We will create a simple login form with username and password fields, along with a submit button to authenticate the user. Let’s get started!
Step 1: Install Tkinter
Tkinter is included with Python, so you don’t need to install anything extra. If you are using Python 2.x, you will need to install Tkinter separately with the following command:
pip install tk
Step 2: Import the necessary libraries
We will start by importing the Tkinter module along with the messagebox module for displaying messages to the user.
import tkinter as tk
from tkinter import messagebox
Step 3: Create the main window
Next, we will create the main window for our login app using the Tk class. We will set the title, size, and background color of the window.
root = tk.Tk()
root.title("Login App")
root.geometry("300x200")
root.configure(bg="lightblue")
Step 4: Create username and password fields
Now, let’s create the username and password input fields using the Entry class. We will also add labels to identify each field.
username_label = tk.Label(root, text="Username", bg="lightblue")
username_label.pack()
username_entry = tk.Entry(root)
username_entry.pack()
password_label = tk.Label(root, text="Password", bg="lightblue")
password_label.pack()
password_entry = tk.Entry(root, show='*')
password_entry.pack()
Step 5: Create the submit button
We will create a submit button that will call a function to validate the username and password entered by the user.
def login():
username = username_entry.get()
password = password_entry.get()
if username == "admin" and password == "admin123":
messagebox.showinfo("Login Successful", "Welcome, Admin!")
else:
messagebox.showerror("Login Failed", "Invalid username or password")
submit_btn = tk.Button(root, text="Submit", command=login)
submit_btn.pack()
Step 6: Run the main loop
Finally, we will run the main loop to display the login app window and wait for user input.
root.mainloop()
And that’s it! You have successfully created a Login App GUI using Python’s Tkinter library in just 30 minutes. Feel free to customize the design and functionality according to your requirements.
I hope you found this tutorial helpful. Happy coding!
Thank you so much. Best explanation. Kudos to you sir 😊
bahut pasand aaya maza aagaya
SIR, ACTUALLY ITS SAYING WRONG KEYWORD " FILE " ITRIED TO FIX IT WITH YOUR PROBLEM BUT NO SOLUTION PLEASE HELP
4TH GRADE STUDENT STRUGLLING FROM ERRORS
nice teacher
sir , how to access a logo file from file explorer to vs code , please reply
Good work
Sir please help me
12:00
Just amazing! Great work sir, very helpful for me Thank sir very much:)
no pip install. pillow
Thanks sir
sir you solve my problem I don't have words to say thanx
"favicon.ico" jaisi file kaise banaye
how to create image file in python
Unable to resize the image… it's appearing "Module img has no attribute named resize"
Actually I am facing problem while adding the images and icon on idle and I can't install pycharm…..pls help me it's my school project and I ahve to submit this on day after tomorrow pls help
Can we make this on idle python instead of pycharm
root = Tk()
in this line it gives me error saying 'TclError: couldn't connect to display ":5.0"'
Thankyou Sir!
I wish i could use front end technologies(html/css) for GUI in tkinter.