class CustomTimeDialog(simpledialog.Dialog): def body(self, master):…
- User
class CustomTimeDialog(simpledialog.Dialog): def body(self, master): self.timebutton_style = {"font": ("consolas", 11), "fg": "white", "bg": "#3c3c3c", "relief": "flat"} self.title('Custom Time') master.configure(bg=self.time_background)
self.listbox = tk.Listbox(master, height=7, width=15, font=("Arial", 12)) for time_string in ['0:15', '0:30', '0:45', '1:00', '2:00', '5:00', '10:00']: self.listbox.insert(tk.END, time_string) self.listbox.pack() self.listbox.bind('<<ListboxSelect>>', self.set_spinboxes_from_selection) # Main frame to contain the minutes and seconds frames time_frame = tk.Frame(master, bg=self.time_background) time_frame.pack(side=tk.TOP, fill=tk.X, padx=5, pady=5) # Create a frame for the minutes spinbox and label minutes_frame = tk.Frame(time_frame) minutes_frame.pack(side=tk.LEFT, fill=tk.X, padx=5) tk.Label(minutes_frame, text="Minutes:").pack(side=tk.TOP) self.spin_minutes = tk.Spinbox(minutes_frame, from_=0, to=59, width=5, font=("Arial", 12)) self.spin_minutes.pack(side=tk.TOP) # Create a frame for the seconds spinbox and label seconds_frame = tk.Frame(time_frame, bg=self.time_background) seconds_frame.pack(side=tk.LEFT, fill=tk.X, padx=5) tk.Label(seconds_frame, text="Seconds:").pack(side=tk.TOP) self.spin_seconds = tk.Spinbox(seconds_frame, from_=0, to=59, width=5, font=("Arial", 12), wrap=True) self.spin_seconds.pack(side=tk.TOP) return self.spin_seconds # initial focus def buttonbox(self): box = tk.Frame(self) self.ok_button = tk.Button(box, text="Apply", width=10, command=self.ok, default=tk.ACTIVE) self.ok_button.config(**self.timebutton_style) self.ok_button.pack(side=tk.TOP, padx=5, pady=5) box.pack() def set_spinboxes_from_selection(self, event=None): index = self.listbox.curselection() if not index: return time_string = self.listbox.get(index) minutes, seconds = map(int, time_string.split(':')) self.spin_minutes.delete(0, tk.END) self.spin_minutes.insert(0, minutes) self.spin_seconds.delete(0, tk.END) self.spin_seconds.insert(0, seconds) def apply(self): minutes = int(self.spin_minutes.get()) seconds = int(self.spin_seconds.get()) self.result = minutes * 60 + seconds def validate(self): try: minutes = int(self.spin_minutes.get()) seconds = int(self.spin_seconds.get()) if seconds < 60: return True else: self.bell() return False except ValueError: self.bell() return Falseset the background color of each element to #808080 so that the window's background is uniform of #808080
- Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.