-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworldwidetime.py
47 lines (31 loc) · 1.03 KB
/
worldwidetime.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import tkinter as tk
import pytz
from datetime import datetime
def show_time():
# Get the city name from the input field
city = city_entry.get()
# Use pytz to get the timezone for the given city
tz = pytz.timezone(city)
# Get the current time in the specified timezone
time = datetime.now(tz)
# Format the time as a string
time_string = time.strftime("%I:%M %p %Z")
# Update the label with the current time
time_label.config(text=time_string)
# Create the main window
root = tk.Tk()
root.title("City Time")
# Create a label for the city input field
city_label = tk.Label(root, text="Enter a city name:")
city_label.pack()
# Create a city input field
city_entry = tk.Entry(root)
city_entry.pack()
# Create a button to show the time
time_button = tk.Button(root, text="Show Time", command=show_time)
time_button.pack()
# Create a label to display the time
time_label = tk.Label(root, text="")
time_label.pack()
# Run the tkinter event loop
root.mainloop()