Quote (DeadShell @ Jun 6 2011 11:51pm)
CAUSE IT"S GAY
now duct, tell me why there are errors in this. Python breaks my balls, it's too format whore for me.
Codefrom Tkinter import *
from tkMessageBox import showerror
import shelve
shelvename = 'class-shelve'
fieldnames = ('name', 'age', 'job', 'pay')
def makeWidgets():
global entries
window = Tk()
window.title('Records Entry')
form = Frame(window)
labels = Frame(form)
values = Frame(form)
labels.pack(side=LEFT)
values.pack(side=RIGHT)
form.pack()
entries = {}
for label in ('key',) + fieldnames:
Label(labels, text=label).pack()
ent = Entry(values)
ent.pack()
entries[label] = ent
Button(window, text="Fetch", command=fetchRecord).pack(side=LEFT)
Button(window, text="Update", command=updateRecord).pack(side=LEFT)
Button(window, text="Quit", command=window.quit).pack(side=RIGHT)
return window
def fetchRecord():
key = entries['key'].get()
try:
record = db[key]
except:
showerror(title='Error', message='No such key')
else:
for field in fieldnames:
entries[field].delete(0, END)
entries[field].insert(0, repr(getattr(record, field)))
def updateRecord():
key = entries['key'].get()
if key in db.keys():
record = db[key]
else:
from person import Person
record = Person(name='?', age='?')
for field in fieldnames:
setattr(record, field, eval(entries[field].get()))
db[key] = record
db = shelve.open(shelvename)
window = makeWidgets()
window.mainloop()
db.close()
Your first for loop seems a bit weird. Change it to
Code
for label in ('key') and fieldnames:
Label(labels, text=label).pack()
ent = Entry(values)
ent.pack()
entries[label] = ent
Just guessing here, so I could be wrong.
Quote (rockonkenshin @ Jun 7 2011 04:20am)
You'll fit right in with the rest of the douchebags that work at Best Buy.
I'm trying to get a job there.
This post was edited by BreakPoint on Jun 7 2011 10:04am