Nub needs help withTkinter

Bob van der Poel bvdpoel at kootenay.com
Mon Dec 8 13:41:27 EST 2003



Agency wrote:
>>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.

Or look on my website for the countbeats program I wrote awhile ago. I 
think this is what you're trying to do ... but no reason not to reinvent 
the wheel if you want :)

-- 
Bob van der Poel ** Wynndel, British Columbia, CANADA **
EMAIL: bvdpoel at kootenay.com
WWW:   http://www.kootenay.com/~bvdpoel





More information about the Python-list mailing list