创建一个时钟,但不是在新的 window 中而是在程序本身中
Create a clock but not in a new window but in the programme itself
是否可以在 Python 程序上创建一个时钟,它会不断更新但不会出现在新的 window 上?
原因,我尝试在 Google 上查找,但许多结果是在新的 window 上创建数字时钟,
期望的结果:
23:59
谢谢
import os
import datetime
import time
#function to clear the screen
def cls():
os.system('cls' if os.name=='nt' else 'clear')
while True:
cls()
now = datetime.datetime.now()
print (now.strftime("%Y-%m-%d %H:%M:%S"))
time.sleep(1)
上面的代码片段会很好。然而,这种方法与其说是“创建时钟”,不如说是“显示计算机的时间值”
是否可以在 Python 程序上创建一个时钟,它会不断更新但不会出现在新的 window 上?
原因,我尝试在 Google 上查找,但许多结果是在新的 window 上创建数字时钟,
期望的结果:
23:59
谢谢
import os
import datetime
import time
#function to clear the screen
def cls():
os.system('cls' if os.name=='nt' else 'clear')
while True:
cls()
now = datetime.datetime.now()
print (now.strftime("%Y-%m-%d %H:%M:%S"))
time.sleep(1)
上面的代码片段会很好。然而,这种方法与其说是“创建时钟”,不如说是“显示计算机的时间值”