Tkinter, scale widget, and mouse clicks

J

John Fouhy

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)
 
K

klappnase

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
 
J

John Fouhy

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,
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top