Python Tkinter Files | PGDCA Sem II

Python Logo

Tkinter is the inbuilt python module that is used to create GUI applications. It is one of the most commonly used modules for creating GUI applications in Python as it is simple and easy to work with. You don’t need to worry about the installation of the Tkinter module separately as it comes with Python already. It gives an object-oriented interface to the Tk GUI toolkit.

Here below you can see some Python Coding for ‘Student Record’ project:

This code is for UserID and Password Input Module :

from tkinter import *
import mysql.connector
import tkinter as tk
con=mysql.connector.connect(host='localhost',user='root',passwd='', database='pythondb')
top=Tk()

uidvar=tk.StringVar()
pvar=tk.StringVar()
def submit():
    u=uidvar.get()
    p=pvar.get()
    print("user id-",u)
    print('password-',p)
    cur=con.cursor()
    sql='insert into login(userid,password) values(%s,%s)'
    val=(u,p)
    try:
        cur.execute(sql,val)
        con.commit()
    except:
        con.rollback()

top.geometry("700x500")
l1=tk.Label(text="Create New User",font=('calibre',12,'bold'))
l1.place(x=300,y=20)
uidl=tk.Label(text="User ID",font=('calibre',10,'bold'))
uidl.place(x=100,y=60)
t1=tk.Entry(top,textvariable=uidvar)

t1.place(x=180,y=60)
pl=tk.Label(text="Password",font=('calibre',10,'bold'))
pl.place(x=100,y=90)
t2=tk.Entry(top,textvariable=pvar)
t2.place(x=180,y=90)
btn=tk.Button(text="Save Record",command=submit)
btn.place(x=250,y=130)
top.mainloop()
con.close()

NOTE : This code will only work if you have connected your MySQL Server or Host to the module.

Install XAMPP

Click on below hyperlink to download the XAMPP Installer File

File will be uploaded soon!!!

You may also like...