Tkinter, scale widget, and mouse clicks

klappnase klappnase at web.de
Wed Jun 23 01:40:36 CEST 2004


jfouhy at paradise.net.nz (John Fouhy) wrote in message news:<c0f3aa87.0406211518.240493f5 at posting.google.com>...
> So I've got a horizontal scale widget in my GUI.  When I click the
> mouse in the area to the right of the GUI, the scale advances by 1.
> 
>                         13                         
>              +-------------------------+
>              |<|       [===]     X   |>|
>              +-------------------------+
>                           
>                         ||
>                         \/
> 
>                         14                         
>              +-------------------------+
>              |<|        [===]        |>|
>              +-------------------------+
> 
> I want to change this, so it jumps by a larger amount (and likewise if
> I click to the left of the slider).
> 
> Any clues?
> (setting 'bigincrement' only works for CTRL-left / CTRL-right when the
> widget has keyboard focus)

You can address the part of the scale widget you clicked on with
event.x/event.y, so maybe something like this might do what you want
(untested):

var = IntVar()
var.set(0)
sb = Scrollbar(master, variable=var)
sb.bind('<1>', jump)

def jump(event):
    if sb.identify(event.x, event.y) == 'trough1':
        var.set(var.get()-5)
        return 'break'
    elif sb.identify(event.x, event.y) == 'trough2':
        var.set(var.get()+5)
        return 'break'

I hope this helps

Michael



More information about the Python-list mailing list