×

How to create a login page in python

Users can access an application by providing their username and Password or by authenticating with a social media login on the login screen.

Python Tkinter

Python provides a variety of choices for GUI development. Tkinter is the approach used the most frequently among all GUI approaches. It is a standard Python interface for the Python-supplied Tk GUI toolkit. The fastest and most straightforward approach to constructing GUI apps is with Python and Tkinter. Tkinter makes building a GUI a simple process.

Python Tkinter for GUI

One of the most common GUI application components is the login form.

Users that use the Login Form can log in with their user name and Password. The user may be granted privileged access when the credentials have been verified.

Theme Behind the login page created:

In this illustration, we create a program that launches a window with fields for the user name and Password and a submit button.

The user can click the Login button after entering their username and Password.

A function is run to verify the username and Password after clicking the button. You must write your application logic to verify the username and credentials in this function.

For this illustration, we retrieve the user's username and Password from the credential verifying function and print them to the application window.

For starting with the code, we can segregate the program into different sections:

Importing modules section

We have to import the Tkinter module.

We use Tkinter to create the GUI application in python; in this program, we mainly use the Tkinter module, so we first have to import the Tkinter module.

Creating the Mainframe

We will now build the application's primary frame after importing the components.

Designing the Layout

Following the development of the Main Frame, the application will receive some layout. Here we use the grid format to align the labels and input fields.

Initializing the Application

We will now execute the application in the infinite loop so that the main screen can be visible to the user continually until the user exits the page.

Python code for login page

from Tkinter import *
from functools import partial


def validateLogin(username, password):
	print ("User has entered the username :", username.get())
	print ("User has entered the password :", password.get())
	return


# Creating the GUI window 
console = Tk () # Initialization of Tkinter
console.geometry('400x300')  # Size of the window
console.title('Login page for using python Tkinter code')


# Creating input of username 
Label1 = Label (console, text="User Name"). grid (row=0, column=0) # Label to specify Username
Input1 = StringVar() 
# Inputing the user’s name
usernameEntry = Entry (console, text variable = Input1). grid (row=0, column=1)  


# Creating input of Password
# Label to specify Login
Label2 = Label(console,text="Password").grid(row=1, column=0)  
Input2 = StringVar()
# Inputing the Password
passwordEntry = Entry (console, text variable = Input2, show='*'). grid (row=1, column=1)  


validateLogin = partial (validateLogin, Input1, Input2)


# Creating login button
loginButton = Button (console, text="Login", command=validateLogin). grid (row=4, column=0)  


console.mainloop()

The above is used to create the login page with a GUI, which inputs the two String inputs one is a username, and the other is a Password. And we can validate the user by the two inputs taken using validate function.

When this code is executed, the output screen is the simple user interface that inputs the username and Password and contains a login button. On clicking the login button after entering the username and Password and in the above code, we have printed the username and Password entered by the user.

The following is the output window after executing the above-given code:

How to create a login page in python

Here we are taking the two inputs:

Username and Password for verifying the credentials of a user.

Here the username and Password are printed on the output console after entering the user credentials, that is, username and password, using the general print method in python. The following is the picture of the output window after entering the username and Password and clicking the login button.

How to create a login page in python

To display stars when the user types the Password, we used Entry (.., show = '*') for the Password.

Of course, you can enhance the labels and GUI window. However, because the main focus of this tutorial is on the functionality of a login form, we continue with the standard style of GUI elements.


Related Topics

Python Matrix Multiplication

One of the most fundamental mathematical structures, matrices are used often in many disciplines, including mathematics, physics, engineering, computer science, etc. For example, matrices and associated operations (multiplication and addition) are...

8 minutes read.

Colors in Python

Adding colour to your visualisations will help them come to life. Even if you know the colours you want to use, picking good ones and putting them into practise might...

4 minutes read.

Python Statistical Module

Python Statistical Module The Python statistical module provides various functions that we can use in our Python program, to perform mathematical statistics operations on the numerical data given to us. The...

8 minutes read.

Python: SetBitmap() function in wxPython

SetBitmap() function In the last tutorial, we have discussed about the GetLabelText() function of wx.MenuItem class which is one of the important function of this class. Now, in this tutorial, we...

6 minutes read.

Data Class in Python

Introduction In Python 3.7, the dataclass modules are introduced as a practical tool for creating organized classes designed specifically for data storage. These classes contain specific attributes and capabilities to deal...

6 minutes read.

How to Plot Graphs Using Python?

In this article, we are going to learn about how to plot different types of graphs using Python. We are going to use different approaches for every type of graph....

3 minutes read.

Python Scikit-image | Image Processing Using Scikit-Image

What is Image Processing? The world is defined with images and, every image has its different specialties. An image can contain much-needed information that can be helpful in various ways. The process...

4 minutes read.

Cx_Oracle Python with Example

Python Programming Language: Python programming language is one of the most used programming languages, as it is used widely in the field of software and data analysis, web development, etc. It...

6 minutes read.

Linear Regression using Sklearn with Example

This article will examine Python's global, local and non-local variables and show you how to use them to write code without problems. Let's quickly review what a variable in Python is...

8 minutes read.

Python History

Python is one of the top trending, widely-used programming languages. Python is a general-purpose programming language. Python language is known for its features. Some features are given below: SimplisticFree and open...

4 minutes read.

Python Sending Email

Python Sending Email Simple Mail Transfer Protocol (SMTP) is used to handle sending e-mail and routing e-mail between mail servers. When we send an email either form a web-application or from a local software...

3 minutes read.

EDA in Python

The EDA is the exploratory data analysis; the data scientists mainly use the EDA to understand the main features of the data quickly, the variables in python and the relationship...

6 minutes read.

_dict_ in Python

An unordered collection of data values known as a dictionary can be used in Python to store data values similar to a map. Dictionaries can also store a key: value...

6 minutes read.

Subprocess in Python

In this tutorial, we will understand what is a subprocess in python and will understand how to use it. Subprocess A subprocess is a very prevailing portion of the python library. It...

3 minutes read.

Python Read CSV file

The CSV stands for “comma-separated value,” which is defined as a simple file format that is used to store data into a tabular form such as a database or spreadsheet. It is...

7 minutes read.

Why learn Python?

All things considered, learning python would be extraordinary, it'll acquaint you with the universe of dynamic programming dialects, if you're somebody who has had a semester of involvement with C. Python...

4 minutes read.

Python Coroutine

Introduction In Python, Coroutines are defined as the special type of function that freely allows control to its caller without losing the state. Coroutines and generates are similar but coroutines consist...

3 minutes read.

Filter List in Python

Python: Python is one of the most used programming languages, as it is used widely in software and data analysis, web development, etc. It is said to be a user-friendly programming...

3 minutes read.

Python String startswith() method

Python String startswith() method The string.startswith() method in Python returns a boolean value ‘True’ if the given string starts with the prefix, otherwise it returns False. Syntax startswith(prefix[, start[, end]]) Parameter prefix: This parameter signifies the value to check. start(optional):...

1 minute read.

Python Syntax

Python is a strong object-oriented programming language that is simple to learn. Python was created to be a very readable programming language. The syntax of the Python programming language is...

8 minutes read.