Tkinter, scale widget, and mouse clicks

Discussion in 'Python' started by John Fouhy, Jun 22, 2004.

  1. John Fouhy

    John Fouhy Guest

    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)

    --
    John.
     
    John Fouhy, Jun 22, 2004
    #1
    1. Advertising

  2. John Fouhy

    klappnase Guest

    (John Fouhy) wrote in message news:<>...
    > 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
     
    klappnase, Jun 23, 2004
    #2
    1. Advertising

  3. John Fouhy

    John Fouhy Guest

    (klappnase) wrote in message news:<>...
    > (John Fouhy) wrote in message news:<>...
    > > 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.
    > > 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?

    > 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


    I had an idea of doing something like that, but I didn't know about
    the 'identify' function.

    Also, I am using the Scale widget, not the Scrollbar widget, but it
    seems Scale has that function too.

    (I wish Tkinter had better documentation)

    Anyawy, your solution worked perfectly :)

    Thanks a lot,

    --
    John.
     
    John Fouhy, Jun 25, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Fredrik Lundh
    Replies:
    0
    Views:
    521
    Fredrik Lundh
    Aug 19, 2004
  2. Jeff Epler
    Replies:
    0
    Views:
    533
    Jeff Epler
    Aug 20, 2004
  3. Jeff Epler
    Replies:
    0
    Views:
    481
    Jeff Epler
    Aug 23, 2004
  4. Replies:
    0
    Views:
    313
  5. PontiMax

    Clicks and double-clicks

    PontiMax, Jul 14, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    207
    Eliyahu Goldin
    Jul 14, 2004
Loading...

Share This Page