简体   繁体   English

无法实时更新此 GUI 中的时间?

[英]Unable to update the time in this GUI in real time?

import tkinter as tk
from tkinter import ttk
from time import strftime
try:
    from ctypes import windll
    windll.shcore.SetDpiAwareness(1)
except Exception as e:
    pass


class App(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title('Digital Clock')
        self.geometry('290x70')
        self.resizable(False, False)

        def tick():
            set_time = strftime('%H:%M:%S:%p')
            clock_label.config(text=set_time)

        clock_label = ttk.Label(self, font=('calibri', 40, 'bold'),
                                background='yellow', foreground='black',
                                )
        clock_label.grid(row=0, column=0)
        clock_label.after(100, tick)


if __name__ == '__main__':
    digiclock = App()
    digiclock.mainloop()`
```

The time after being set dont update itself after using the after method on label.在标签上使用 after 方法后,设置后的时间不会自行更新。 Why its not doing so and how to correct it?为什么它不这样做以及如何纠正它?

Here you can see nothing appears into the window while after method used within the the tick() method在这里,您可以看到在 tick() 方法中使用 after 方法时窗口中没有任何显示

import tkinter as tk
from tkinter import ttk
from time import strftime
try:
    from ctypes import windll
    windll.shcore.SetDpiAwareness(1)
except Exception as e:
    pass


class App(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title('Digital Clock')
        self.geometry('290x70')
        self.resizable(False, False)

        def tick():
            set_time = strftime('%H:%M:%S:%p')
            clock_label.config(text=set_time)

        clock_label = ttk.Label(self, font=('calibri', 40, 'bold'),
                                background='yellow', foreground='black',
                                )
        clock_label.grid(row=0, column=0)
        clock_label.after(100, tick)


if __name__ == '__main__':
    digiclock = App()
    digiclock.mainloop()`
```

The time after being set dont update itself after using the after method on label.在标签上使用 after 方法后,设置后的时间不会自行更新。 Why its not doing so and how to correct it?为什么它不这样做以及如何纠正它?

Here you can see nothing appears into the window while after method used within the the tick() method在这里,您可以看到在 tick() 方法中使用 after 方法时窗口中没有任何显示

import tkinter as tk
from tkinter import ttk
from time import strftime
try:
    from ctypes import windll
    windll.shcore.SetDpiAwareness(1)
except Exception as e:
    pass


class App(tk.Tk):
    def __init__(self):
        super().__init__()
        self.title('Digital Clock')
        self.geometry('290x70')
        self.resizable(False, False)

        def tick():
            set_time = strftime('%H:%M:%S:%p')
            clock_label.config(text=set_time)

        clock_label = ttk.Label(self, font=('calibri', 40, 'bold'),
                                background='yellow', foreground='black',
                                )
        clock_label.grid(row=0, column=0)
        clock_label.after(100, tick)


if __name__ == '__main__':
    digiclock = App()
    digiclock.mainloop()`
```

The time after being set dont update itself after using the after method on label.在标签上使用 after 方法后,设置后的时间不会自行更新。 Why its not doing so and how to correct it?为什么它不这样做以及如何纠正它?

Here you can see nothing appears into the window while after method used within the the tick() method在这里,您可以看到在 tick() 方法中使用 after 方法时窗口中没有任何显示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM