Hello there, I am trying to write a script for an old 133mhz laptop I have, that will bind every key to different functions, and on a key press a different image, or video will be displayed, and/or a sound file. I have figured out how to bind keys with tkinter, and I have figured out how to display images on a canvas, providing I keep the code seperate, but when I put them together it doesn't work. I would like the image and/or movie to show up on the main tkinter window that starts up, as I will have this fullscreen. Any suggestions would be GREATLY appreciated, as I am really sick right now and spent a good deal of the night trying to figure this out. I am a newbie to python too, which should be obvious. :)
The functions were just defined for testing, so I know where to put code later on.
from Tkinter import *
canvas = Canvas(width = 300, height = 200, bg = 'yellow')
canvas.pack(expand = YES, fill = BOTH)
gif1 = PhotoImage(file = 'getstart.gif')
canvas.create_image(50, 10, image = gif1, anchor = NW)
def press_a(event):
print 'You Pressed a'
def press_b(event):
print 'You pressed b'
def press_c(event):
print 'You pressed c'
def press_d(event):
print 'You pressed d'
def press_e(event):
print 'You pressed e'
def press_f(event):
print 'You pressed f'
def press_g(event):
print 'You pressed g'
def press_h(event):
print 'You pressed h'
def press_i(event):
print 'You pressed i'
def press_j(event):
print 'You pressed j'
def press_k(event):
print 'You pressed k'
def press_l(event):
print 'You pressed l'
def press_m(event):
print 'You pressed m'
def press_n(event):
print 'You pressed n'
def press_o(event):
print 'You pressed o'
def press_p(event):
print 'You pressed p'
def press_q(event):
print 'You pressed q'
def press_r(event):
print 'You pressed r'
def press_s(event):
print 'You pressed s'
def press_t(event):
print 'You pressed t'
def press_u(event):
print 'You pressed u'
def press_v(event):
print 'You pressed v'
def press_w(event):
print 'You pressed w'
def press_x(event):
print 'You pressed x'
def press_y(event):
print 'You pressed y'
def press_z(event):
print 'You pressed z'
def press_1(event):
print 'You pressed 1'
def press_enter(event):
print 'You pressed enter'
root = Tk()
frame = Frame(root, width=500,height=500)
Tkinter.Label(frame, image='c:\blah.bmp')
root.bind('a', press_a)
root.bind('b', press_b)
root.bind('c', press_c)
root.bind('d', press_d)
root.bind('e', press_e)
root.bind('f', press_f)
root.bind('g', press_g)
root.bind('h', press_h)
root.bind('i', press_i)
root.bind('j', press_j)
root.bind('k', press_k)
root.bind('l', press_l)
root.bind('m', press_m)
root.bind('n', press_n)
root.bind('o', press_o)
root.bind('p', press_p)
root.bind('q', press_q)
root.bind('r', press_r)
root.bind('s', press_s)
root.bind('t', press_t)
root.bind('u', press_u)
root.bind('v', press_v)
root.bind('w', press_w)
root.bind('x', press_x)
root.bind('y', press_y)
root.bind('z', press_z)
root.bind('1', press_1)
root.bind('<Enter>', press_enter)
frame.pack()
canvas.mainloop()
root.mainloop()