from datetime import datetime import pytz import tkinter as tk # 都市とタイムゾーン cities = { "Japan (Tokyo)" : "Asia/Tokyo", "Thailand (Bangkok)" : "Asia/Bangkok", "India (Delhi)" : "Asia/Kolkata", "Ukraine (Kyiv)" : "Europe/Kyiv", "Germany (Berlin)" : "Europe/Berlin", "UK (London)" : "Europe/London", "New York" : "America/New_York", "Los Angeles" : "America/Los_Angeles" } # メインウィンドウ root = tk.Tk() root.title("World Clock") root.geometry("500x350") # タイトル title = tk.Label( root, text="World Clock", font=("Arial", 20, "bold") ) title.pack(pady=10) # 時計表示ラベル labels = {} for city in cities: label = tk.Label( root, text="", font=("Courier", 14), anchor="w" ) label.pack(fill="x", padx=20) labels[city] = label # 時刻更新関数 def update_clock(): for city, timezone in cities.items(): tz = pytz.timezone(timezone) now = datetime.now(tz) current_time = now.strftime("%Y-%m-%d %H:%M:%S") labels[city].config( text=f"{city:<22} : {current_time}" ) # 1000ms後に再実行 root.after(1000, update_clock) # 更新開始 update_clock() # GUI開始 root.mainloop()