我正在學習/嘗試tkinter,并嘗試使用 aDoubleVar來存盤來自Scale小部件的資料并通過Label.
這作業正常,但它顯示的有效數字水平比我想要的要高得多。這是我應該在Label側面或DoubleVar側面控制的東西,我將如何做到這一點?
coefficient_of_resitution_value = tk.DoubleVar()
coefficient_of_resitution_slider = ttk.Scale(coefficient_of_restitution_frame,
from_ = 0,
to = 1,
orient = "horizontal",
variable = coefficient_of_resitution_value,
style = "white_background_scale.Horizontal.TScale")
coefficient_of_resitution_slider.grid(column = 0, row = 1, columnspan = 1, sticky = tk.NSEW)
coefficient_of_resitution_display = ttk.Label(coefficient_of_restitution_frame,
textvariable = coefficient_of_resitution_value,
background = "#FFFFFF",
font = ("Calibri", 16))
coefficient_of_resitution_display.grid(column = 1, row = 0, sticky = tk.NSEW)
uj5u.com熱心網友回復:
一種方法是在command選項的回呼中將值四舍五入為您想要的值:
coefficient_of_resitution_slider['command'] = \
lambda val: coefficient_of_resitution_value.set(round(float(val), 4))
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/369275.html
