notes/Basic GTK GUI to add Entry to MySQL DataBase-gTtgBtwr.py
#!/usr/bin/python
import gtk
import MySQLdb as mdb
import sys
def send_press(widget):
try:
con = mdb.connect('localhost', 'root', 'root', 'test');
cur = con.cursor()
cur.execute("INSERT INTO table1(name) VALUES('" + entry.get_text() + "')")
cur.execute("SELECT * FROM table1")
rows = cur.fetchall()
for row in rows:
print row
except mdb.Error, e:
print "Error %d: %s" % (e.args[0],e.args[1])
sys.exit(1)
finally:
if con:
con.close()
win=gtk.Window()
win.connect('destroy', lambda w: gtk.main_quit())
box = gtk.VBox()
win.add(box)
entry=gtk.Entry()
box.pack_start(entry)
send=gtk.Button("SEND")
send.connect("clicked", send_press)
box.pack_start(send)
win.show_all()
gtk.main()
syntax highlighted by Code2HTML, v. 0.9.1