python3使用tk画一个编辑框获取当前时间
下面是使用tkinter库创建一个编辑框并获取当前时间的Python3代码示例:
import tkinter as tk
import time
def get_current_time():
current_time = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
text_box.insert(tk.END, current_time + '\n')
root = tk.Tk()
root.title("Current Time")
# 创建一个编辑框
text_box = tk.Text(root, height=10, width=40)
text_box.pack()
# 创建一个按钮
button = tk.Button(root, text="获取当前时间", command=get_current_time)
button.pack()
root.mainloop()
运行这个程序,将会创建一个窗口,包含一个编辑框和一个按钮。当用户点击“获取当前时间”按钮时,程序将会获取当前时间并将其添加到编辑框中
原文地址: https://www.cveoy.top/t/topic/fmL2 著作权归作者所有。请勿转载和采集!