要在表格中顯示實時時間并實時變動,可以使用Python的datetime
庫。以下是一個簡單的示例:
import datetime
from tkinter import *
def update_time():
current_time = datetime.datetime.now()
label.config(text=str(current_time))
root = Tk()
label = Label(root, font=('Helvetica', 16), bg='white')
label.pack()
update_button = Button(root, text="更新時間", command=update_time)
update_button.pack()
root.mainloop()
這段代碼將創(chuàng)建一個Tkinter窗口,其中包含一個標簽和一個按鈕。當點擊按鈕時,程序會獲取當前時間并將其顯示在標簽上。
本文內容根據網絡資料整理,出于傳遞更多信息之目的,不代表金鑰匙跨境贊同其觀點和立場。
轉載請注明,如有侵權,聯系刪除。