我正在编写一个GUI,您必须在其中输入一个数字。我想要一个天平,但它很符合我的目的。问题是天平的精度是1e-9。这对我来说非常精确。我正在为tkinter
使用ttk
扩展。我试过一些方法,但是我看到有一个数字选项,当有一个StringVar()
时,它会留下数字,但是它不起作用,它不能识别这个选项。我试着去图书馆找,但什么也找不到,太复杂了
我的代码是这样形成的:
scaleValue = StringVar()
scale = ttk.Scale(content, orient=HORIZONTAL, from_=1, to=5, variable=scaleValue, length=150, digits=1) # here digits ins't recongnised
scale.grid(column=x, row=y)
scaleValueLabel = ttk.Label(content, textvariable=scaleValue)
scaleValueLabel.grid(column=x', row=y')
以下是文档:
An integer specifying how many significant digits should be retained when converting the value of the scale to a string. Official Documentation : http://www.tcl.tk/man/tcl8.6/TkCmd/scale.htm
digits
是仅对tk.Scale
可用的参数。如果您切换到使用它,那么您的代码将正常工作:但是如果您真的想使用
ttk.Scale
,您可以使用不同的方法。与在Label
中使用textvariable
不同,您可以跟踪变量上的更改,首先处理值,然后传递回Label
相关问题 更多 >
编程相关推荐