Nub needs help withTkinter

Agency image9n at hotmail.com
Mon Dec 8 13:17:28 EST 2003


> You will need to __bind__ a callback to the key press on a widget. 
> something like :-
> 
> 
> 
> from Tkinter import *
> 
> 
> root=Tk()
> lab = Label(root, text = "Beat Counter : ")
> lab.pack()
> 
> beats = 0
> 
> 
> 
> def beatCounter(event):
>     print "increment counter"
>     global beats
>     beats = beats + 1
>     lab.config(text = "Beat Counter : %d" %beats)
>     
> def beatReset(event):
>     print "reset counter"
>     global beats
>     beats = 0 
>     lab.config(text = "Beat Counter : %d" %beats)
>     
>     
> root.bind("<space>", beatCounter)
> root.bind("<Return   >", beatReset)
> 
> 
> root.mainloop()
> 
> 
> You should rewrite the above so it does not use the global statement
> ('cause thats cheating!)
> 
> 
> 
> HTH
> Martin
-------------------------------------------------------------------------
Wow. Thats perfect. I'm not sure what you meant about the global
statement, this is my first time trying to program anything, but I'll
look through the docs and see if I find something out. Now, I just
have figure out how this codes works and have it correspond to a clock
function on a display, which gives the bpm.

Thanks, I was getting rather frustrated. I'll post back if I get
stumped.




More information about the Python-list mailing list