Creating a more complex clock with multiple options in Python can involve additional functionality like setting alarms, changing time zones, using analog display, etc. For the purpose of this response, I will keep it relatively simple while introducing some additional features like changing clock modes (24-hour and 12-hour) and allowing the user to change the clock's color scheme. We'll stick to a digital display for simplicity.
Below is an example of a Python code that creates a digital clock GUI with these features using the tkinter library:
import tkinter as tk
from tkinter import ttk
from time import strftime
class Clock(tk.Tk):
def __init__(self):
super().__init__()
self.title("Customizable Clock")
self.geometry("300x150")
self.resizable(False, False)
# Create a time display label
self.time_label = tk.Label(self, font=('Arial', 30), background='black', foreground='white')
self.time_label.pack(expand=True)
# Options for clock customization
self.clock_mode = tk.BooleanVar(self, value=True) # True for 24-hour mode, False for 12-hour mode
mode_button = ttk.Checkbutton(self, text="24-hour mode", variable=self.clock_mode, command=self.update_clock)
mode_button.pack(side=tk.BOTTOM)
self.color_var = tk.StringVar(self)
self.color_var.set("white")
color_label = tk.Label(self, text="Select clock color:")
color_label.pack(side=tk.LEFT)
color_options = ttk.Combobox(self, textvariable=self.color_var, values=["white", "green", "blue", "red"], state="readonly")
color_options.pack(side=tk.LEFT)
color_options.bind('<<ComboboxSelected>>', self.change_color)
self.update_clock()
def update_clock(self):
if self.clock_mode.get():
# 24-hour format
current_time = strftime('%H:%M:%S')
else:
# 12-hour format
current_time = strftime('%I:%M:%S %p')
self.time_label.config(text=current_time)
self.after(1000, self.update_clock) # Schedule this method to be called after 1000ms
def change_color(self, event=None):
color = self.color_var.get()
self.time_label.config(foreground=color)
if __name__ == "__main__":
clock_app = Clock()
clock_app.mainloop()
This script has a Checkbutton that allows the user to toggle between a 24-hour and a 12-hour clock display format. It also has a Combobox to select different colors for the clock text. The change_color method is bound to the <<ComboboxSelected>> event and updates the color of the clock display whenever a new color is selected from the dropdown menu.
These new features make the clock more interactive and customizable, giving the user some control over how the clock appears and functions. You can further extend this code by adding more options and features, such as setting up alarms, changing fonts, or displaying different time zones.