Tkinter Scale and floats at resolution> 1
How do I get float values ββfrom the scale when the resolution is higher than 1? If I set the resolution below 1, for example 0.9, the Scale will give floats. Above is 1 and all I can get are integers.
Sample code:
from tkinter import * root = Tk() var = DoubleVar() scale = Scale(root, variable=var, resolution=3.4) scale.pack() label = Label(root, textvariable=var) label.pack() root.mainloop()
I am using Python 3.4.1 64-bit on Windows 7.
+3
source to share
1 answer
Scale () widget problems Visual MVC
DoubleVar()
does not allow control over the UI representation (Visual-part) Scale()
(decimal depth) and part of the model remains valid (although hidden, can be checked through aScaleINSTANCE.get()
).
Workaround layout:
from tkinter import * # python 3+
root = Tk()
varAsTxt = StringVar() # an MVC-trick an indirect value-holder
aScale = Scale( root,
variable = varAsTxt, # MVC-Model-Part value holder
from_ = -10.0, # MVC-Model-Part value-min-limit
to = 10.0, # MVC-Model-Part value-max-limit
length = 600, # MVC-Visual-Part layout geometry [px]
digits = 4, # MVC-Visual-Part presentation trick
resolution = 0.23 # MVC-Controller-Part stepping
)
aScale.pack()
root.lift()
0
source to share