Skip to content

Instantly share code, notes, and snippets.

@ayutaz
Created December 23, 2018 12:39
Show Gist options
  • Save ayutaz/81aefd2d111d9c4af46ae4a853a01377 to your computer and use it in GitHub Desktop.
Save ayutaz/81aefd2d111d9c4af46ae4a853a01377 to your computer and use it in GitHub Desktop.
GUI(tkinter)を使い,時刻を表示する No.3 ref: https://qiita.com/ayousanz/items/109eed7dbf8286db87a3
from datetime import datetime
import tkinter
import time
w=800
h=600
root1=tkinter.Tk()
root1.title("timer")
root1.geometry("800x450")
canvas=tkinter.Canvas(root1,width=w,heigh=h)
canvas.pack()#ここを書かないとcanvasがうまく入らない.
while True:
now_h=datetime.now().hour
now_s=datetime.now().second
now_m=datetime.now().minute
now_time=str(now_h)+":"+str(now_m)+":"+str(now_s)
canvas.create_text(w/2,200,text=now_time,font=("",50,"italic"),tag='Y') #タグを入れることで更新できるようにする.
canvas.update()
canvas.delete('Y')
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment