Link to home
Start Free TrialLog in
Avatar of lessthan2
lessthan2

asked on

How can I create a python (Tkinter) form that will search a mysql table for a specific row, then allow me to UPDATE that row.

How can I create a python/Tkinter form that allows me to search for a particular row in a MySQL table, then UPDATE that row as needed.
I got some help last week from cxr (expert) in putting together a form (see below) that we use to INSERT new records. We've been able to modify what cxr did, such that it now works for other, larger tables.
If someone could assist me with some modifications to this code, we'll be able to take it from there.
Thanks
#!/usr/bin/python
from Tkinter import *
import MySQLdb
 
## Connect to DB
conn = MySQLdb.connect(host='localhost', user='root', db='mind0')
##Create a cursor
curs = conn.cursor() 
## *****************************************************
# Root level form
class MyApp:
  def __init__(self):
    window = Tk()
    window.title('Data Entry Form')   
    frame = Frame(window)
    frame.pack()
## BEGIN Fields ***********************************************     
    self.fields = {}
#--------------    
    l = Label(frame, text="vendID:")
    l.grid(row=0, column=0)    
    self.fields['vendID'] = Entry(frame)
    self.fields['vendID'].grid(row=0, column=1)    
#--------------      
    l = Label(frame, text="vendName:")
    l.grid(row=2, column=0)   
    self.fields['vendName'] = Entry(frame)
    self.fields['vendName'].grid(row=2, column=1)
## END Fields ************************************************    
 
## BEGIN Buttons ########         
    submitbtn = Button(frame, text="Find", command=self.do_insert)
    submitbtn.grid(row=11, column=0)
    
    clearbtn = Button(frame, text="Clear", command=self.do_clear)
    clearbtn.grid(row=11, column=1)
## END Buttons ##########    
    window.mainloop()
 
## Insert and Clear functions 
  def do_clear(self):  
    self.fields['vendID'].delete(0,END)
    self.fields['vendName'].delete(0,END)
 
  def do_insert(self):
  	global curs
	sql = "insert into vendor (vendID,vendName) values ('%s','%s');"%( 
		self.fields['vendID'].get(),
		self.fields['vendName'].get())
	curs.execute(sql)
	print sql
                   
if __name__=="__main__":
    MyApp()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Roger Baklund
Roger Baklund
Flag of Norway image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of lessthan2
lessthan2

ASKER

cxr, thanks for the solution (I was hoping you'd take my question). With a couple minor edits, it works fine for doing INSERTs, and UPDATEs.
Next, I'm going to try and build some searching functionality into these forms. If I end up needing some guidance, I'll post another question. Keep an eye out for me.