【发布时间】:2016-05-14 17:41:58
【问题描述】:
我正在尝试在 python 中创建一个全屏时钟,它将使用 tkinter 显示全屏。
到目前为止,我有 2 位代码可以工作,用于创建全屏 tkinter 窗口,并使用 strftime 打印时间。
尝试将 2 位代码合并在一起是我的头脑 - 我可以让一个时钟在 shell 中运行,或者一个显示时间但不更新的 tkinter 窗口。
我需要在 tkinter 窗口中显示时间,并且每 0.5 秒更新一次时间。
下面是我所拥有的 - 它远未完成。 非常感谢任何帮助。 乔恩
import sys
if sys.version_info[0] == 2:
from Tkinter import *
import Tkinter as tk
else:
from tkinter import *
import tkinter as tk
import time
from time import *
import os
from os import *
clock = tk.Tk() # make it cover the entire screen
w, h = clock.winfo_screenwidth(), clock.winfo_screenheight()
clock.overrideredirect(1)
clock.geometry("%dx%d+0+0" % (w, h))
clock.focus_set() # <-- move focus to this widget
clock.bind("<Escape>", lambda e: e.widget.quit())
###############this is the problem...
while True:
time = strftime("%A, %d %B %Y %X")
sleep (0.5)
#print (time)
###############this is the problem...
text = Text(clock)
text.insert(INSERT, time)
text.pack()
clock.mainloop()
【问题讨论】: