当分辨率 > 时,Tkinter 缩放和浮动1 [英] Tkinter Scale and floats when resolution > 1
本文介绍了当分辨率 > 时,Tkinter 缩放和浮动1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当分辨率高于 1 时,如何从 Scale 获取浮点值?如果我将分辨率设置为低于 1,例如 0.9,Scale 将给出浮点数.高于 1,我只能得到整数.
How do I can get float values from Scale when the resolution is above 1? If I set the resolution below 1, for example 0.9, Scale will give floats. Above 1, and all I can get is integers.
示例代码:
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()
我在 Windows 7 上使用 Python 3.4.1 64 位.
I'm using Python 3.4.1 64-bit on Windows 7.
推荐答案
Scale() 小部件 MVC 可视化部分的问题
DoubleVar()
不允许控制 Scale()
(小数位深度)的 UI 呈现(Visual-part),而 Model-part保持正确(虽然隐藏,但可能会通过 aScaleINSTANCE.get()
进行检查).
Troubles with the Scale() widget MVC Visual-part
DoubleVar()
does not allow to control UI presentation ( Visual-part ) of the Scale()
( a depth of decimal places ), while a Model-part remains correct ( though hidden, might get inspected via aScaleINSTANCE.get()
).
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()
这篇关于当分辨率 > 时,Tkinter 缩放和浮动1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文