Python Tkinter — Login Form

Python has a design philosophy which emphasizes code readability. That’s why python is very easy to use especially for beginners who just started programming. It is very easy to learn the syntax emphasizes readability and it can reduces time consuming in developing.

  1. Login Form is one of the most used in GUI applications.
  2. Login Form helps users to login using user name and password.
  3. Once the credentials are validated, user can be given privileged access.

Getting started:

First you will have to download & install the Python IDLE’s, here’s the link for the Integrated Development And Learning Environment for Python https://www.python.org/downloads/

Installing SQLite Browser:

After you installed Python, we will now then install the SQLite, here’s the link for the DB Browser for SQLite http://sqlitebrowser.org/

Importing Modules:

After setting up the installation and the database, run the IDLE and click file and then new file. After that a new window will appear containing a black file this will be the text editor for the python.

Setting up the Main Frame:

After importing the modules, we will now then create the main frame for the application. To do that just copy the code below and paste it inside the IDLE text editor.

root = Tk()

root.title(“Python: Simple Login Application”)

width = 400

height = 280

screen_width = root.winfo_screenwidth()

screen_height = root.winfo_screenheight()

x = (screen_width/2) — (width/2)

y = (screen_height/2) — (height/2)

root.geometry(“%dx%d+%d+%d” % (width, height, x, y))

root.resizable(0, 0)

Designing the Layout :

After creating the Main Frame we will now add some layout to the application. Just kindly copy the code from google and paste it inside the IDLE text editor.

Creating the Database Connection :

Then after setting up the design we will now create the database function. To do that just simply copy the code below and paste it inside the IDLE text editor

def Database():

global conn, cursor

conn = sqlite3.connect(“pythontut.db”)

cursor = conn.cursor()

cursor.execute(“CREATE TABLE IF NOT EXISTS `member` (mem_id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, username TEXT, password TEXT)”)

cursor.execute(“SELECT * FROM `member` WHERE `username` = ‘admin’ AND `password` = ‘admin’”)

if cursor.fetchone() is None:

cursor.execute(“INSERT INTO `member` (username, password) VALUES(‘admin’, ‘admin’)”)

conn.commit()

Creating the Main Function :

This is the main function where the Entry will be check if there is a user exist in the database, after login correctly a new window will pop up. To do that just simply copy the code below then paste it inside the IDLE text editor.

Initializing the Application :

After finishing the function save the application as ‘index.py’. This function will run the code and check if the main is initialize properly. To do that copy the code below and paste it inside the IDLE text editor.

Summary

we learned to create a Login Form in Python GUI application using tkinter.

Get practical training in Data Science, Web Development, Mobile App Development, Ui-Ux, Flutter, Python, Machine Learning, & much more in Mumbai.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store