Registration Login and Listing of Users

Basics of Python Tkinter

Connect to MySQL database Add record using sqlalchemy.
Main window will have three buttons, asking users to Register , Login or to display User List. These three buttons trigger three functions

Login registration main Window
  1. my_registarion()
  2. my_login()
  3. user_list()
Here is the basic structure of the script divided into three parts. You can read any part independently by visiting the respective link above.

Database connection

We can use MySQL or SQLite database for our script. We have commented the SQLite connection string here but you can enable it and remove MySQL part. We used sqalchemy as database connection engine.
from sqlalchemy import create_engine
my_conn = create_engine("mysql+mysqldb://userid:password@localhost/my_database")
#my_conn = create_engine("sqlite:///my_db_mem.db") # SQLite database 

Changes required while using SQLite

Enable the SQLite connection and disable the MySQL connection ( check the above line ). Passing the parameters with database query. In case of MySQL we used this
my_query="INSERT INTO mem(name,userid,password) values(%s,%s,%s)"
In case of SQLite we have to change the query like this.
my_query="INSERT INTO mem(name,userid,password) values(?,?,?)"
In all places we have to change the query part using this. No need to change any other part of the script.
from sqlalchemy import create_engine
my_conn = create_engine("mysql+mysqldb://id:password@localhost/my_database")
#my_conn = create_engine("sqlite:///my_db_mem.db") # SQLite database 
import tkinter as tk
from tkinter import * 
my_w = tk.Tk()
my_w.geometry("300x200") 

my_font1=('times', 18, 'bold')
my_str1 = tk.StringVar()
l1 = tk.Label(my_w,  textvariable=my_str1, fg='red',font=my_font1, width=16 )
l1.grid(row=1,column=1,columnspan=2,sticky='E') 
my_str1.set("plus2net.com")


b1 = tk.Button(my_w, text='Register', width=24,command=lambda:my_registration())
b1.grid(row=3,column=2)

b2 = tk.Button(my_w, text='Login', width=24,command=lambda:my_login())
b2.grid(row=4,column=2)

b3 = tk.Button(my_w, text='User List', width=24,command=lambda:user_list())
b3.grid(row=5,column=2)
#### End of main window #### 
def my_registration():
Registration Login Listing
View and Download tkinter-mysql-insert.ipynb file

Displaying records from student table
Detail sqlalchemy Database Error message from MySQL


plus2net.com



Post your comments , suggestion , error , requirements etc here





Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer