更改python tkinter比例中的槽增量,而不影响滑块

时间:2017-03-16 19:41:26

标签: python tkinter tkinter-scale

当您在python tkinter比例中单击槽(滑块的任一侧)时,滑块会向左/右移动一个增量。

如果您按住鼠标,它将更快地移动,使用repeatdelay&按repeatInterval。

我想要的是,当您在槽中单击时,滑块会以更大的增量移动,而不会失去使用滑块以较小的步长递增的能力。

我已经研究过scale小部件,并且可以看到它有一个bigincrement字段,这意味着支持这个,但是我不确定何时使用bigincrement?

我还查看了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() ,它确实改变了滑块跳跃的数量,但它失去了通过拖动滑块来微调它的能力。

那么,每次点击低谷时,如何配置缩放以使用bigincrement作为增加比例的值。并且仍然可以拖动滑块以获得更细粒度的增量?

示例代码:

class Processor implements Runnable {

    private int id;
    private Integer interaction;
    private Set<Integer> subset;
    private static volatile AtomicBoolean notRemoved = new AtomicBoolean(true);

    public Object<E> dcp;
    public Iterator<Integer> iterator;



    public Processor(int id, Integer interaction, Set<Integer> subset, Object<E> dcp, Iterator<Integer> iterator) {
        this.id = id;
        this.interaction = interaction;
        this.subset= subset;
        this.dcp = dcp;
        this.iterator = iterator;
    }

    public void run() {
        while (Processor.notRemoved.get()){
            System.out.println("Starting: " + this.id);
            if (this.dcp.PA.contains(this.interaction)){
                this.subset.add(this.interaction);
                this.dcp.increaseScore(this.subset);
                if (!this.subset.contains(this.interaction) && Processor.notRemoved.get()){
                    Processor.notRemoved.set(false);
                    iterator.remove();
                }
            }

            System.out.println("Completed: " + this.id);
        }   
    }
}


public class ConcurrentApp {

    public void mainFunction (Object<E> dcp, int threads) {

        ExecutorService executor = Executors.newFixedThreadPool(threads);

        int i =1;
        while ((dcp.PA.size() > i) && (i <= dcp.R)){
            for (Iterator<Integer> iterator = dcp.PA.iterator(); iterator.hasNext();){
                Integer interaction = iterator.next();
                ArrayList<Integer> removed = new ArrayList<Integer>(dcp.PA);
                removed.remove(interaction);
                ArrayList<Set<Integer>> subsets = dcp.getSubsets(removed, i);
                for (int j = 0; j< subsets.size(); j++){
                    executor.submit(new Processor(j, interaction, subsets.get(j), dcp, iterator));
                }
                executor.shutdown();
                System.out.println("All tasks submitted");
                try {
                    executor.awaitTermination(1, TimeUnit.DAYS);
                } catch (InterruptedException e) {
                    System.out.println("HERE");
                    e.printStackTrace();
                }
            }
            System.out.println("All tasks completed");
            i++;
        }   
    }
}

1 个答案:

答案 0 :(得分:0)

使用resolution参数。

请参阅the docs,尤其是“绑定”部分中的第1点。

编辑:如果要在不影响分辨率的情况下更改增量,则必须劫持滑块的工作方式。您可以制作自己的滑块版本:

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()
相关问题