class CustomTimeDialog(simpledialog.Dialog): def body(self, master): self.title('Custom…
- User
class CustomTimeDialog(simpledialog.Dialog): def body(self, master): self.title('Custom Time Dialog')
codeself.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) tk.Label(master, text="Minutes:").pack(side=tk.LEFT) self.spin_minutes = tk.Spinbox(master, from_=0, to=59, width=5, font=("Arial", 12)) self.spin_minutes.pack(side=tk.LEFT) tk.Label(master, text="Seconds:").pack(side=tk.LEFT) self.spin_seconds = tk.Spinbox(master, from_=0, to=59, width=5, font=("Arial", 12), wrap=True) self.spin_seconds.pack(side=tk.LEFT) return self.spin_minutes # initial focusreaarrange the “minute”" and “seconds:” text of the spinbox on top of the corresponding spinbox input instead of next to it. so the text “minutes:” would be on top of minute spinbox and “seconds” on top of seconds spinbox. just rearrange don't add anything else
- Assistant
To rearrange the labels so that they are above the corresponding spinboxes, you need to change the packing order and use the
pack()method with appropriate side and anchor arguments. You will also need to create frames to contain each label and spinbox pair to achieve the desired layout. - User
class CustomTimeDialog(simpledialog.Dialog): def body(self, master): self.title('Custom Time Dialog')
codeself.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) # Create a frame for the minutes spinbox and label minutes_frame = tk.Frame(master) minutes_frame.pack(side=tk.TOP, fill=tk.X, padx=5, pady=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(master) seconds_frame.pack(side=tk.TOP, fill=tk.X, padx=5, pady=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 - Assistant
To arrange the seconds spinbox and label to the right of the minutes spinbox and label, you will need to adjust the packing of the frames. Instead of packing both the and to the top of the master, you will pack them side by side, using . Using frames allows each set to be grouped together, making it easy to control the layout.