以下是一个简单的示例代码:

import tkinter as tk
import time

def get_time():
    current_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
    text.insert(tk.END, current_time + '\n')

root = tk.Tk()
root.title('时间编辑器')

text = tk.Text(root, height=10, width=50)
text.pack()

button = tk.Button(root, text='获取当前时间', command=get_time)
button.pack()

root.mainloop()

运行代码,将打开一个窗口,其中包含一个文本框和一个按钮。每次单击按钮时,将在文本框中插入当前时间。

Python3 使用 Tkinter 创建时间编辑器:获取并显示当前时间

原文地址: https://www.cveoy.top/t/topic/oc36 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录