当我将滑块向下移动到更低的值(例如,到40)时,标签中的第三个数字仍然显示?
我怎么才能解决这个问题呢?
import tkinter as tk
class App(tk.Tk):
def __init__(self):
super().__init__()
# BMP display
def bmp_print(*args):
self.bmp_number = tk.Label(self, text=[self.w1.get()], fg = 'red', font=('Times', 60))
self.bmp_number.place(x = 725, y = 140)
# self windows size
window_width = 1024
window_height = 600
# get the screen dimension
screen_width = self.winfo_screenwidth()
screen_height = self.winfo_screenheight()
# find the center point
center_x = int(screen_width/2 - window_width / 2)
center_y = int(screen_height/2 - window_height / 2)
# set the position of the window to the center of the screen
self.geometry(f'{window_width}x{window_height}+{center_x}+{center_y}')
# Resize main window xy, on/off, 0 or 1 .
self.resizable(0, 0)
# Main window on top of stack.
self.attributes('-topmost', 1)
# Create slider
self.w1 = tk.Scale(self, from_=240, to=40, command = bmp_print)
self.w1.set(240)
self.w1.place(x = 150, y=400)
if __name__ == "__main__":
app = App()
app.mainloop()
预计当结果从三位数值变为两位数值时,标签将显示两位数值,而不显示剩余的第三位数值.