Python program for login page using Tkinter package

In this program, we are going to discuss how we can implement the login page in python using the Tkinter package.

Create a login page using Tkinter in Python

1st of all in the login page we have to design a window with two buttons one for login button and another one is register button.

Let’s move on the code 1st import the Tkinter package.

from tkinter import *

Create a function which generates a login window with a login page as a title.

def main_screen():
    mainscreen = Tk()   # create a GUI window 
    mainscreen.geometry("800x800") # set the configuration of GUI window 
    mainscreen.title(" Login Page") # set the title of GUI window

Create a level for some message:

# create a Form label 
Label(text="Login Window Example", bg="blue", width="30", height="2", font=("Calibri", 13)).pack() 
Label(text="").pack()

Now, at last, we have to create two buttons: Register button and a Login button.

# create Login Button 
Button(text="Login", height="2", width="30").pack() 
Label(text="").pack() 

# create a register button
Button(text="Register", height="2",width="30").pack()

You should learn more about pack() from the depth: Tkinter pack(), grid() Method In Python

Finally, start the window and call the main_screen function:

 
mainscreen.mainloop() # start the GUI

main_screen() # call the main_account_screen() function

Now combine the whole program into a single program so that you can understand what we did.

from tkinter import *
#Designing Main Screen So, first of all, you have to design the main screen.
#two buttons Login and Register.
def main_screen():
    mainscreen = Tk()   # create a GUI window 
    mainscreen.geometry("800x800") # set the configuration of GUI window 
    mainscreen.title(" Login Page") # set the title of GUI window

# create a Form label 
Label(text="Login Window Example", bg="blue", width="30", height="2", font=("Calibri", 13)).pack() 
Label(text="").pack() 

# create Login Button 
Button(text="Login", height="2", width="30").pack() 
Label(text="").pack() 

# create a register button
Button(text="Register", height="2",width="30").pack()
 
mainscreen.mainloop() # start the GUI

main_screen() # call the main_account_screen() function

 

Output:

login page using tkinter package

 

Also, read;

3 responses to “Python program for login page using Tkinter package”

  1. chakradhar says:

    You made it easy for beginners. next step would have been even more great.

  2. Harish says:

    In line 20,it will raise error
    Because mainscreen was define in main_screen() not in main program. When you not call this function or leave this function it will raise error

  3. bob says:

    This script didn’t work for me I got:
    AttributeError: ‘function’ object has no attribute ‘tk’

    I think you have to define your mainscreen as a variable first and not as a function call. I.e just “main_screen=tk()”

Leave a Reply

Your email address will not be published. Required fields are marked *