Hi I am fairly new to python
and was wondering if anyone out there could help me optomize this code.
It is a simple Tkinter program that connects to a database and deletes
records
Some of this code was borrowed from a book learning python
Anyhelp would be cool thank you in advance
Andrew
"""""Below is the code"""""
import MySQLdb
from Tkinter import *
class FormEditor:
def __init__(self):
self.row = 0
self.current = None
self.root = root = Tk()
root.minsize(300, 200)
root.rowconfigure(0, weight=1)
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=2)
Label(root, text='Form Editor App', font='bold').grid(columnspan=2)
self.row = self.row + 1
self.listbox = Listbox(root, selectmode=SINGLE)
self.listbox.grid(columnspan=2, sticky=E+W+N+S)
self.listbox.bind('<ButtonRelease>')
self.row = self.row + 1
self.add_button(self.root, self.row, 0, 'Delete Entry',
self.delentry)
self.add_button(self.root, self.row, 1, 'Reload', self.load_data)
self.load_data()
def add_button(self, root, row, column, text, command):
button = Button(root, text=text, command=command)
button.grid(row=row, column=column, sticky=E+W, padx=5, pady=5)
def load_data(self):
self.db = MySQLdb.connect("localhost", "", "", "guestbook")
self.c = self.db.cursor()
self.c.execute("select * from guests;")
self.results = self.c.fetchall()
self.listbox.delete(0, END)
for item in self.results:
self.listbox.insert(END, item)
def delentry(self):
self.db = MySQLdb.connect("localhost", "", "", "guestbook")
self.c = self.db.cursor()
self.c.execute("DELETE FROM guests WHERE id LIMIT 1;")
self.results = self.c.fetchall()
print "Please press reload to see your results"
app = FormEditor()
app.mainloop()