Question : 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
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
#!/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 Select All

Answer : 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.

Make an update-button, attach it to this method:
1:
2:
3:
4:
5:
6:
7:
  def do_update(self):
        global curs
        sql = "update vendor set vendName='%s' where vendID='%s')"%( 
                self.fields['vendName'].get(),
                self.fields['vendID'].get())
        curs.execute(sql)
        print sql
Open in New Window Select All
Random Solutions  
 
programming4us programming4us