Nub needs help withTkinter

Eric Brunel eric.brunel at
Mon Dec 8 10:08:29 CET 2003

Agency wrote:
> I'm trying to program a utility that counts the beats per minute in a
> song
> by tapping the spacebar. I already have a program that does this, but
> I wanted to make my own. The "enter" key resets the counter to zero
> along with one of two displays. I'm importing Tkinter and this is what
> I have so far. I get a syntax error at this spot ----->   
> <KeyPress-space>
> Any thoughts how to get the keypress to increase the counter better?
> Is it possible to convert it to an int or something?
> ------------------------------------------------------------------
> from Tkinter import *
> root = Tk()
> w = Label(root, text="The BPM Counter")
> w.pack()
> class display1:
>     def beat():
>         beat = 0
>         if beat > 10000:
>             beat += <KeyPress-space>
> root.mainloop()
> -------------------------------------------------------------------

I can't even begin to undeerstand what you're trying to do here: 
<KeyPress-space> is only valid in a string as an event description that you can 
pass to the various bind methods, so converting it to an int has no meaning at 
all for me...

Maybe you should begin with a tutorial for Tkinter; you'd surely understand 
better what's going on and how you can do things with it. "Thinking in Tkinter" 
is usually a good place to start:
(follow the link all_programs.html to get the full the whole series of scripts 
and the explanations around them).

- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools -

More information about the Python-list mailing list