Saturday, May 16, 2020

Python Program to retrieve a row from a MYSQL database table using GUI

 
So another example this time with GUI retrieves a row using GUI -- Python a GUI application

#Program: 

import MySQLdb
from tkinter import *

root = TK() # create root window

def retrieve_rows(eno): # takes employee number and display
    conn = MYSQLdb.connect(host = 'localhost' , database = 'Anything' , user = 'root' , password ='Pass123')
cursor = conn.cursor()

     str = "select * from table where eno = '%d'"
args = (eno)
cursor.execute(str % args)
row = cursor.fetchone()
 
if row is not None:
     lbl = Label(text=row,font=('Arial' , 14)).place(x=50, y=200)
 
cursor.close()
     conn.close()

#takes input from Entry widget
def display(self): 
    str =e1.get()
    lbl =Label(text='You entered: '+str,font=('Arial' , 14)).place(x=50, y=150) 
    retrieve_rows(int(str)
# create a frame as child to root window
f = Frame(root, hegight=350,width=600)
f.propagete(0)
f.pack()

l1=Label(text='Enter employee number : ',font=('Arial' , 14))

e1 = Entry(f,width=15 , fg='blue' , bg='yellow',font=('Arial',14))
e1.bind(("<Return>" , display)
l1.place(x=50,y=100)
e1.place(x=300,y=100)

root.mainloop()

Output: 








No comments: