[Tutor] Tkinter event handler
CF
jakhead at gmail.com
Fri Jan 13 20:50:41 CET 2012
I apologize, I didn't realize how tired I was. I've got it working,
sort of, after finding the event.char attribute. I needed it to work
via keyboard since I don't use a mouse often and I'm running this with
awesome-wm's launcher so it can't get input from the terminal (as far
as I know) and I didn't know another way to have it prompt me for
input except with Tk. Here's what I've got:
def key(event):
class_list = read_object('.create_note_classes') # pickle file
list of class names
class_list.sort()
class_name = class_list[int(event.char) - 1]
id = new_id() # this gets the appropriate number for filename ex: 001
today = get_date() # gets date and formats it
filename = '%03d_%s_%s.org' % (id, today, class_name)
## ex: 001_Jan_13_2012_Economics.org
window.destroy()
subprocess.call(['emacs', filename])
class_list = read_object('.create_note_classes')
class_list.sort()
window = Tk()
for i, v in enumerate(class_list):
v = Label(text='%d %s' % (i + 1, v)).pack()
window.bind_all('<key>', key)
window.mainloop()
I'm going to change this to use the listbox widget though since you
mentioned it. It's ugly I know, this is the first thing I've tried
writing with python (2.7 btw).
More information about the Tutor
mailing list