[Tkinter-discuss] Kinetic Scrolling and Keyboard Shortcuts in Menus

Guilherme Polo ggpolo at gmail.com
Sun Aug 31 19:03:14 CEST 2008


On Sun, Aug 31, 2008 at 1:11 AM, Johnston Jiaa <oclbdk at gmail.com> wrote:
> I'm having trouble trying to make a kinetic scrolling canvas.  The code
> looks something like this...
>
> def scroll(acceleration, speed):
>        while speed >= 0:
>                canvas.xview_scroll(-speed, "units")
>                speed -= acceleration
>
> This doesn't update the drawing of the canvas in real-time (as in, every
> time xview_scroll is called)... it only updates the drawing after the while
> loop has already run, so you don't get to see it scroll, which is stupid.
>  How can I get this to work properly?

You will need a canvas.update() after that .xview_scroll
But, why aren't you using "after" instead of a while loop for this ?

>
>
> Also, I have set keyboard shortcuts for some functions in my program.  The
> functions these shortcuts call are also linked to menu items in the menu
> bar.  How can I get the menu labels to reflect the keyboard shortcuts for
> each relative command?  I know I can set the shortcut as a string in the
> label manually, but it will be stupid, not flush with the right edge of the
> menu, like in other programs.
>

There are actually two question here.

For the later the answer is.. instead of setting the shortcut it in
the label, use the accelerator option to set it.
The former is about reflecting keyboard shortcuts in menu labels, for
this you will need to roll your own solution or try finding someone
that already did it.

>
> Thanks for helping my program not be stupid
> _______________________________________________
> Tkinter-discuss mailing list
> Tkinter-discuss at python.org
> http://mail.python.org/mailman/listinfo/tkinter-discuss
>



-- 
-- Guilherme H. Polo Goncalves


More information about the Tkinter-discuss mailing list