1

When you click in the trough (either side of the slider) in a python tkinter scale, the slider moves one increment to the left/right.

If you hold the mouse, it will move more quickly, using repeatdelay & repeatinterval.

What I would like, is to have the slider move in bigger increments when you single click in the trough, without losing the ability to use the slider to increment by smaller steps.

I have researched the scale widget, and can see it has a bigincrement field, which is meant to support this, but I'm not sure when bigincrement is used?

I've also looked at resolution, which does change the amount the slider jumps, but it loses the ability to fine tune it by dragging the slider.

So, how can I configure the scale to use bigincrement as the value to increment the scale, each time the trough is clicked. And still be able to drag the slider to get finer grained increments?

Example code:

from Tkinter import *

master = Tk()

w = Scale(master, from_=0, to=100, bigincrement=10)
w.pack()

w = Scale(master, from_=0, to=200, orient=HORIZONTAL, bigincrement=100)
w.pack()

mainloop()
finefoot
  • 9,914
  • 7
  • 59
  • 102
R.Jarvis
  • 273
  • 2
  • 8

1 Answers1

0

Use the resolution argument.

See the docs, especially point 1 in the "bindings" section.

EDIT: If you want to change the increment without affecting the resolution, you will have to hijack the way the slider works. You could make your own version of a slider like this:

import Tkinter as tk

class Jarvis(tk.Scale):
    '''a scale where a trough click jumps by a specified increment instead of the resolution'''
    def __init__(self, master=None, **kwargs):
        self.increment = kwargs.pop('increment',1)
        tk.Scale.__init__(self, master, **kwargs)
        self.bind('<Button-1>', self.jump)

    def jump(self, event):
        clicked = self.identify(event.x, event.y)
        if clicked == 'trough1':
            self.set(self.get() - self.increment)
        elif clicked == 'trough2':
            self.set(self.get() + self.increment)
        else:
            return None
        return 'break'

# example useage:
master = tk.Tk()
w = Jarvis(master, from_=0, to=200, increment=10, orient=tk.HORIZONTAL)
w.pack()
w = Jarvis(master, from_=0, to=200, increment=30, orient=tk.HORIZONTAL)
w.pack()
master.mainloop()
Novel
  • 13,406
  • 2
  • 25
  • 41
  • This does change the increment when the trough is clicked, but it also affects the slider. I'd still like to be be able to use the slider to increment by 1 (or more) but set it so that clicking the trough causes bigger jumps... – R.Jarvis Mar 16 '17 at 20:51
  • Ahh I missed that requirement in your OP. I edited my post with another solution. – Novel Mar 16 '17 at 21:06