Add some space between the border and the text: 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
To add some space between the border and the text in your show_datatype_dialog method, you can adjust the padding inside the content_frame. By increasing the padx and pady parameters in the pack method of content_frame, you create more space between the border and the content inside the frame.
Here's the modified code with the adjustments:
python
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"])
# Increased padding to add space between the border and the text
content_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(content_frame, bg=self.colors["background"])
# Optionally, add padding inside each row frame
frame.pack(fill=tk.X, pady=2, padx=5)
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)
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(content_frame, bg=self.colors["header_info"], height=1)
separator.pack(fill=tk.X, pady=(5, 5))
apply_label = tk.Label(
content_frame,
text="Apply Changes",
bg=self.colors["background"],
fg=self.colors["text"],
font=self.fonts["text"],
cursor="hand2"
)
apply_label.pack()
apply_label.bind("<Button-1>", lambda e: self._apply_changes())
def on_label_enter(event):
event.widget.config(bg=self.colors["button_selected"])
def on_label_leave(event):
event.widget.config(bg=self.colors["background"])
apply_label.bind("<Enter>", on_label_enter)
apply_label.bind("<Leave>", on_label_leave)
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()
By setting padx=10 and pady=10, you add 10 pixels of horizontal and vertical padding around the content_frame, which increases the space between the border and the content.
Optional Padding in Each Row Frame:
python
frame.pack(fill=tk.X, pady=2, padx=5)
Adding padx=5 to each row frame (frame) provides additional horizontal space between the content inside the content_frame and its edges.
Explanation:
Padding (padx and pady): Padding adds space around the widget inside its container. Increasing the padding in the pack method of content_frame effectively adds space between the border (defined by border_frame) and the text/content inside content_frame.
Optional Row Padding: If you find that you need more space within each row (between the labels/options and the edges of the popup), adding padx to the frame.pack() call inside the loop can help.
Result:
These adjustments will create more space between the border of your popup window and the text/content, making the interface cleaner and easier on the eyes.
Note:
Feel free to adjust the padding values (padx and pady) to suit your preferences. Increasing these values will add more space, while decreasing them will tighten the layout.