簡體   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()`
```

在標簽上使用 after 方法后,設置后的時間不會自行更新。 為什么它不這樣做以及如何糾正它?

在這里,您可以看到在 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()`
```

在標簽上使用 after 方法后,設置后的時間不會自行更新。 為什么它不這樣做以及如何糾正它?

在這里,您可以看到在 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()`
```

在標簽上使用 after 方法后,設置后的時間不會自行更新。 為什么它不這樣做以及如何糾正它?

在這里,您可以看到在 tick() 方法中使用 after 方法時窗口中沒有任何顯示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM