TechSupportNepTechSupportNep - Programming & Tech

  • Home
  • C#.NET
  • PHP
  • JAVA
  • Python
  • ASP.NET
  • VB.NET
  • Android
  • C
  • Tech
    • Tech News
  • Patreoner
TechSupportNep
  • Home
  • Programming
  • Python
  • How to Create Login Application in Python using SQLite Database?
Python

How to Create Login Application in Python using SQLite Database?

By Er. Ran Bahadur B.K. Last updated Aug 15, 2021
1 1,869
Share

Creating Login application in python programming language requires two major task. One is creating GUI and other is implementing logic.

Let’s talk about creating GUI:

Like in other programming language such as C#, You can create windows form application just by drag and dropping controls over the forms. So you may not need to write code to create GUI in C#. But here is python there is no such mechanism so you have to write code to create a GUI. There are various library through which you can create GUI in python. But we are going to use the builtin module that is tkinter. So let’s create the GUI.

We are going to use the intellij IDEA to create this project so download and install it.

Basic project setup STEPS:

  1. Install python in your system, download it from here
  2. Install python plugin in the intellij IDEA from file>setting>plugin and search python and install it.
  3. create virtual environment from file>project structure>SDKs and click on plus sign which you can see on the top of the middle part of the window and select add python SDK. New window pop up and there you can see the virtual env and click OK.
  4. create one project from file>new>project and give project name.
  5. now right click over your project>new>python file give file and and enter.

let’s write the GUI CODE:

STEPS:

 

1. import tkinter and messagebox from tkinter.

import tkinter from tkinter
import messagebox

2. create window then give title and size of window.

main_window=tkinter.Tk()
main_window.title('Login App')
main_window.geometry('400x300')

3. define variable which we will associate with the GUI element to take input from the user.

user_input=tkinter.StringVar()
pass_input=tkinter.StringVar()
padd=20
main_window['padx']=padd

4. write code to design put label and textbox on the window.


info_label=tkinter.Label(main_window, text='Login Application')
info_label.grid(row=0, column=0, pady=20)

info_user=tkinter.Label(main_window, text='Username')
info_user.grid(row=1, column=0)
userinput=tkinter.Entry(main_window, textvariable=user_input)
userinput.grid(row=1, column=1)

info_pass=tkinter.Label(main_window, text='Password')
info_pass.grid(row=2, column=0, pady=20)
passinput=tkinter.Entry(main_window, textvariable=pass_input, show='*')
passinput.grid(row=2, column=1)

login_btn=tkinter.Button(main_window, text='Login', command=login)
login_btn.grid(row=3, column=1)

4. write mainloop method so that our GUI works.

main_window.mainloop()

4. now import sqlite3 so that we can use sqlite in our code.

import sqlite3

5. Define one function and write the following code after defining this function you have one property called command of button and associate that property with this function without writing the parentheses i.e. () because we are not assigning the value return by the function but we are just calling the function by giving it’s name only so that this function will execute normally.[you can see doing this in above code don’t worry it’s for your knowledge]


def login():
db=sqlite3.connect('login.sqlite')
db.execute('CREATE TABLE IF NOT EXISTS login(username TEXT, password TEXT)')
# db.execute("INSERT INTO login(username, password) VALUES('admin', 'admin')")
db.execute("INSERT INTO login(username, password) VALUES('user', 'admin')")
cursor=db.cursor()
cursor.execute("SELECT * FROM login where username=? AND password=?",(userinput.get(), pass_input.get()))
row=cursor.fetchone()
if row:
messagebox.showinfo('info', 'login success')
else:
messagebox.showinfo('info', 'login failed')
cursor.connection.commit()
db.close()

6. Now right click and run the file. That’s all.

 

 

if you have any confusion please watch the following video.

 

Continue Reading
create GUI login apps in pythoncreate GUI login form in pythoncreate login form in pythoncreate login form using pythonhow to create login form in pythonhow to make login app in pythonlogin form in pythonmake login application using pythonmake login form in pythonmake login form using pythonmake python login appspython login applicationpython login appspython login formpython login windowtkinter login apps in pythontkinter login form in python
1 1,869
Share FacebookTwitterReddItWhatsAppPinterestEmail
Er. Ran Bahadur B.K.60 posts 56 comments

Ran Bahadur B.K. is the owner of TechSupportNep who is working with the aim of providing the quality Technology content. He is creating Tech and Programming videos, you can see all them in his YouTube Channel(https://www.youtube.com/TechSupportNep). He is also working with some company.

Prev Post

How to use View Binding in Android?

Show Comments (1)
Help Needed

This website is free of annoying ads. We want to keep it like this. You can help with your support:

Donate!

The need for Support! Why to Support?

If you need your own website? contact me!
erranbahadurbk
Fiverr
Seller
Hello there,This is me Ran Bahadur B.K., A graduated computer engineer. I have 3+ years of work experience in wordpress design and development. I have strong knowledge of HTML, CSS and PHP which are the three ingredients of web development. Currently i am working with the software company so i also have experience in desktop apps and mobile apps development.

Latest

Python

How to Create Login Application in Python using SQLite Database?

How to use View Binding in Android?

Windows 10 Build 1909 Features that you should know.

How to Create a Complete Login and Forgot Password System in java ?

Prev Next 1 of 15
  • About us
  • Contact us
  • Privacy Policy
  • Disclaimer
© 2022 All Rights Reserved.
Website By: Ran Bahadur B.K.