简体   繁体   中英

Tkinter Scale widget with non-integer resolution

I'm trying to add a Tk.Scale widget to my application, but I have a problem with setting non-integer value to the resolution parameter. If I pass an integer value to Scale constructor, it works correctly, but with any non-integer value (say 0.1) my scale widget does not move. It appears at the right place and looks just fine, but doesn't respond to my attempts to move it.

Here is my code related to the creation of scale widget:

    self.sliderValue = Tk.DoubleVar()
    self.slider = Tk.Scale(self.frame,
                           from_=float(self.lowerValue.get()),
                           to=float(self.upperValue.get()),
                           orient=Tk.HORIZONTAL,
                           length=180,
                           variable=self.sliderValue,
                           resolution=0.1, # Here is the problem
                           command=self.sliderMoved)

The problem is I can not reproduce this issue outside of my application. In other words, if I create just a simple window with one scale widget, it works with any resolution values. So it seems that the problem is hidden somewhere outside of this constructor call, but I can not figure out where. May be someone had the same problem and can advise me what should I check.

Addition: May be it is important: in standalone (working) case the value above the slider is in "1.0" format (with the dot as the separator), and in my broken application it is "1,0" format (with the comma as the separator). May by some kind of type/format mismatch is happening here.

Addition 2:

Here is minimal example:

import Tkinter as Tk
from pylab import *

# cla()  # if you uncomment these two lines,
# clf()  # scale will break for non-int resolutions

root = Tk.Tk()

var = Tk.DoubleVar()
scale = Tk.Scale(root, from_=6.0, to=8.5, variable = var,
                resolution=0.1, orient=Tk.HORIZONTAL)
scale.grid(column=0, row=0, columnspan=3)

root.mainloop()

我刚刚更新到 Ubuntu 16.04,这个问题似乎不再出现(Python 2.7.11+)。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM