Advertisement
metalx1000

Basic GTK GUI to add Entry to MySQL DataBase

Aug 19th, 2013
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.82 KB | None | 0 0
  1. #!/usr/bin/python
  2. import gtk
  3. import MySQLdb as mdb
  4. import sys
  5.  
  6. def send_press(widget):
  7.     try:
  8.         con = mdb.connect('localhost', 'root', 'root', 'test');
  9.  
  10.         cur = con.cursor()
  11.         cur.execute("INSERT INTO table1(name) VALUES('" + entry.get_text() + "')")
  12.         cur.execute("SELECT * FROM table1")
  13.  
  14.         rows = cur.fetchall()
  15.  
  16.         for row in rows:
  17.             print row
  18.     except mdb.Error, e:
  19.  
  20.         print "Error %d: %s" % (e.args[0],e.args[1])
  21.         sys.exit(1)
  22.  
  23.     finally:
  24.  
  25.         if con:
  26.             con.close()
  27.  
  28. win=gtk.Window()
  29. win.connect('destroy', lambda w: gtk.main_quit())
  30. box = gtk.VBox()
  31. win.add(box)
  32.  
  33. entry=gtk.Entry()
  34. box.pack_start(entry)
  35.  
  36. send=gtk.Button("SEND")
  37. send.connect("clicked", send_press)
  38. box.pack_start(send)
  39.  
  40.  
  41. win.show_all()
  42.  
  43. gtk.main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement