慕莱坞森
不幸的是,您无法更改显示值的格式。您必须创建自己的标签,而不是使用小部件内置的标签。您可以通过将命令附加到小部件并让该命令更新标签来做到这一点。由于您尝试表示时间,因此我建议将from和to选项设置为秒数,可以轻松地将其重新格式化为分钟和秒。下面是一个自定义类的基本示例,它使用固定标签(即:它保持居中)并将值显示为分钟:秒。import tkinter as tkclass CustomScale(tk.Frame): def __init__(self, master, *args, **kwargs): from_ = kwargs.pop("from_", 0) to = kwargs.pop("to", 120) orient = kwargs.pop("orient", "vertical") super().__init__(*args, **kwargs) self.value_label = tk.Label(self, text="00:00") self.scale = tk.Scale( self, from_=from_, to=to, tickinterval=0, command=self.update_label, showvalue=False, orient=orient ) self.value_label.pack(side="top", fill="x") self.scale.pack(side="bottom", fill="x") def update_label(self, value): value = int(value) minutes = value//60 seconds = value%60 self.value_label.configure(text=f"{minutes:02}:{seconds:02}")root = tk.Tk()scale = CustomScale(root, from_=0, to=120, orient="horizontal")scale.pack(side="top", padx=20, pady=20)root.mainloop()