Modify the code so that there is a fixed width for the datatype boxes: def show_datatype_dialog(self) -> None: """Show custom popup window for changing column data types.""" table_name = self.app.current_table_name if not table_name: messagebox.showwarning("No Table Selected", "Please select a table to change datatypes.") return current_headers = self.app.current_sheet.headers() if self.app.current_sheet else [] self.app.data_manager.headers[table_name] = current_headers self.data_types = self.app.data_manager.tables_data[table_name].get("data_types", []).copy() while len(self.data_types) < len(current_headers): self.data_types.append('string') if hasattr(self, 'datatype_popup') and self.datatype_popup.winfo_exists(): self.datatype_popup.destroy() self.datatype_popup = tk.Toplevel(self.root) self.datatype_popup.overrideredirect(True) border_frame = tk.Frame(self.datatype_popup, bg=self.colors["frame_border"]) border_frame.pack(padx=0, pady=0, expand=True, fill=tk.BOTH) content_frame = tk.Frame(border_frame, bg=self.colors["background"]) content_frame.pack(padx=1, pady=1, expand=True, fill=tk.BOTH) inner_frame = tk.Frame(content_frame, bg=self.colors["background"]) inner_frame.pack(padx=10, pady=10, expand=True, fill=tk.BOTH) self.datatype_vars = {} for header_index, header in enumerate(current_headers): current_type = self.data_types[header_index] frame = tk.Frame(inner_frame, bg=self.colors["background"]) frame.pack(fill=tk.X, pady=2) header_label = tk.Label( frame, text=f"{header}:", bg=self.colors["background"], fg=self.colors["text"], font=self.fonts["text"] ) header_label.pack(side=tk.LEFT, padx=(0, 5)) var = tk.StringVar(value=current_type) option_menu = tk.OptionMenu(frame, var, *self.DATA_TYPE_OPTIONS) option_menu.config( bg=self.colors["background"], fg=self.colors["text"], highlightthickness=0, relief=tk.FLAT ) option_menu["menu"].config(bg=self.colors["background"], fg=self.colors["text"]) option_menu.pack(side=tk.RIGHT) self.datatype_vars[header] = var separator = tk.Frame(inner_frame, bg=self.colors["separator_menu"], height=1) separator.pack(fill=tk.X, pady=(5, 5)) apply_container = tk.Frame( inner_frame, bg=self.colors["background"], cursor="hand2" ) apply_container.pack(fill=tk.X, pady=(5,0)) apply_label = tk.Label( apply_container, text="Apply Changes", bg=self.colors["background"], fg=self.colors["text"], font=self.fonts["text"], cursor="hand2" ) apply_label.pack(expand=True, fill=tk.BOTH, pady=0) def on_hover_enter(event): apply_container.config(bg=self.colors["button_selected"]) apply_label.config(bg=self.colors["button_selected"]) def on_hover_leave(event): apply_container.config(bg=self.colors["background"]) apply_label.config(bg=self.colors["background"]) apply_container.bind("<Enter>", on_hover_enter) apply_container.bind("<Leave>", on_hover_leave) apply_label.bind("<Enter>", on_hover_enter) apply_label.bind("<Leave>", on_hover_leave) apply_container.bind("<Button-1>", lambda e: self._apply_changes()) apply_label.bind("<Button-1>", lambda e: self._apply_changes()) self.datatype_popup.update_idletasks() popup_width = self.datatype_popup.winfo_width() popup_height = self.datatype_popup.winfo_height() screen_width = self.root.winfo_screenwidth() screen_height = self.root.winfo_screenheight() menu_x = self.root.winfo_pointerx() menu_y = self.root.winfo_pointery() padding = 10 if menu_x + popup_width > screen_width - padding: menu_x = screen_width - popup_width - padding if menu_y + popup_height > screen_height - padding: menu_y = screen_height - popup_height - padding menu_x = max(padding, menu_x) menu_y = max(padding, menu_y) self.datatype_popup.geometry(f"+{menu_x}+{menu_y}") def close_popup(event=None): if self.datatype_popup.winfo_exists(): self.datatype_popup.destroy() self.root.unbind("<Button-1>", self.click_outside_popup) self.root.unbind("<Configure>", self.window_resized) def click_outside_popup(event): if not str(event.widget).startswith(str(self.datatype_popup)): close_popup() self.click_outside_popup = self.root.bind("<Button-1>", click_outside_popup) self.window_resized = self.root.bind("<Configure>", lambda e: close_popup()) self.datatype_popup.bind("<FocusOut>", close_popup) self.datatype_popup.bind("<Escape>", close_popup) self.datatype_popup.focus_force()