答案1
要在应用程序中正确显示两个时区,您可以使用 python 和 tkinter。以下是您必须在代码中定义时区的示例:
# importing whole module
from tkinter import *
from tkinter.ttk import *
# importing strftime function to
# retrieve system's time
from time import strftime
from datetime import datetime
from pytz import timezone
tokyo = timezone("Asia/Tokyo")
# creating tkinter window
root = Tk()
root.title('Clock')
# This function is used to
# display time on the label
def time():
local_str = strftime('%H:%M:%S')
tokyo_time = datetime.now(tokyo)
tokyo_str = tokyo_time.strftime('%H:%M:%S')
lbl.config(text = "Local " + local_str + "\nTokyo " + tokyo_str)
lbl.after(1000, time)
# Styling the label widget so that clock
# will look more attractive
lbl = Label(root, font = ('calibri', 40, 'bold'),
background = 'purple',
foreground = 'white',
justify = RIGHT)
# Placing clock at the centre
# of the tkinter window
lbl.pack(anchor = 'center')
time()
mainloop()
当你运行此简短代码时,你将获得如下 GUI