I am learning/trying out tkinter
, and trying to use a DoubleVar
to store the data from a Scale
widget and have it output through a Label
.
This works fine, but it displays to a much higher significant figure level than I would like. Is this something I should control on the Label
side or the DoubleVar
side, and how would I do this?
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)
CodePudding user response:
One of the way is to round the value to what you want inside the callback of command
option:
coefficient_of_resitution_slider['command'] = \
lambda val: coefficient_of_resitution_value.set(round(float(val), 4))