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') self.time_background = "#3c3c3c" self.time_fg="white"
master.configure(bg=self.time_background) self.configure(bg=self.time_background) self.listbox = tk.Listbox(master, height=7, width=15, font=("Arial", 12), bg=self.time_background, fg=self.time_fg) 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, bg=self.time_background) minutes_frame.pack(side=tk.LEFT, fill=tk.X, padx=5) tk.Label(minutes_frame, text="Minutes:", bg=self.time_background, fg=self.time_fg).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:", bg=self.time_background, fg=self.time_fg).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, bg=self.time_background) 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()) return True except ValueError: self.bell() return Falsehow do i make it so that the list show 15s,30s,45s,1m,5m,10m but still set the same value on the spin when clicked
- Assistant
If you want the list to show a different format (like using 's' for seconds and 'm' for minutes) while still setting the correct value in the spinboxes when clicked, you need to update the listbox items to reflect this format and adjust the
set_spinboxes_from_selectionmethod accordingly. Here's how you can do it:First, we change the listbox's items by using 's' for seconds and 'm' for minutes:
#... for time_string in ['15s', '30s', '45s', '1m', '5m', '10m']: self.listbox.insert(tk.END, time_string) #...Next, we adapt the
set_spinboxes_from_selectionmethod to parse both formats: - User
for time_string in ['15s', '30s', '45s', '1m', '5m', '10m']: self.listbox.insert(tk.END, time_string) how do set in center, and style it
- Assistant
To center the text in the
Listboxand style it, you can apply a few modifications to your code. TkinterListboxwidget doesn't directly support text alignment; however, you can work around this limitation by adding spaces before and after your text to create a visual centering effect. For styling purposes, you can specify additional options when creating theListbox.Here's how you might modify the code to center the text and add some styling:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.