class ImageViewer: def init(self, root): self.xgrid=6 self.ygrid=4 def togglegrid(self):…
- User
class ImageViewer: def init(self, root): self.xgrid=6 self.ygrid=4
codedef toggle_grid(self): if self.grid_type == "e" : self.grid_type = "d" else: self.grid_type = "e" griddialog = CustomGridDialog(self.root) self.xgrid= griddialog.xgrid self.ygrid= griddialog.ygrid print (self.grid_type) self.display_image()class CustomGridDialog(simpledialog.Dialog): last_xgrid = 4 last_ygrid = 4 def body(self, master): self.title("Grid Settings") tk.Label(master, text="X").grid(row=0) tk.Label(master, text="Y").grid(row=1)
codeself.x_div_spinbox = tk.Spinbox(master, from_=2, to=20, increment=1, width=2, textvariable=tk.IntVar(value=self.last_xgrid)) self.y_div_spinbox = tk.Spinbox(master, from_=2, to=20, increment=1, width=2, textvariable=tk.IntVar(value=self.last_ygrid)) self.x_div_spinbox.grid(row=0, column=1) self.y_div_spinbox.grid(row=1, column=1) return self.x_div_spinbox # Initial focus def buttonbox(self): box = tk.Frame(self)#, bg=self.time_background) self.ok_button = tk.Button(box, text="Apply", width=16, command=self.ok, default=tk.NORMAL) self.ok_button.pack(side=tk.TOP, ipadx=5, pady=5) box.pack() def ok(self, event=None): self.set_grid_division() self.cancel() # This will close the dialog def set_grid_division(self): self.xgrid = int(self.x_div_spinbox.get()) self.ygrid = int(self.y_div_spinbox.get()) CustomGridDialog.last_xgrid = int(self.x_div_spinbox.get()) CustomGridDialog.last_ygrid = int(self.y_div_spinbox.get())add 3 radio buttons on top that set the spinbox to 0 x 0, 3x3 and 4x4 when pressed. put the spinbox on beside each other. make it so that when the grid spinbox is set to empty, it's set to 0, or if not integer, it's set to 0. and if i close without pressing apply, it closes and does nothing. make the set_grid_division checks that when both of the spinbox is 0, it change the value of self.grid_type="e"
- Assistant
- User
def create_radio_buttons(self, master): self.grid_variable = tk.StringVar(value="") self.radio_buttons_frame = tk.Frame(master) self.radio_buttons_frame.grid(row=0, column=0, columnspan=4)
coderadio_button_values = { "No Grid": "0x0", "3 x 3 Grid": "3x3", "4 x 4 Grid": "4x4" } for (text, value) in radio_button_values.items(): rb = tk.Radiobutton(self.radio_buttons_frame, text=text, variable=self.grid_variable, value=value, command=self.update_spinboxes_from_radio) rb.pack(side=tk.LEFT, padx=5)make the radiobuttons in vertical order
- Assistant
To arrange the radio buttons vertically, you can simply change the
packmethod togridwhen placing your radio buttons withinself.radio_buttons_frame. Additionally, you will set rows for each radio button instead of placing them side by side. Here's the modified version of thecreate_radio_buttonsmethod:python