I am working on a GUI using Customtkinter where I will have multiple inputs in textboxes, using .place() I got my textbox displaying where I wanted it inside of the frame.
However I want the textbox to be longer-
I tried to use .pack(ipadx=90, ipady=10) which are the dimensions I was after, but if I implement this the position of the textbox changes- I seem to only be able to use either .pack() or .place(), however if I use just .pack() I can’t get my desired location and if I use just .place() then I can’t have my desired textbox size.
class root(ctk.CTk):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.title("GenSoft")
self.geometry("800x480")
self.resizable()
self.state("normal")
self.iconbitmap()
self.grid_columnconfigure(1, weight=1)
self.grid_columnconfigure((2, 3), weight=0)
self.grid_rowconfigure((0, 1, 2), weight=1)
self.tabview = ctk.CTkTabview(self,
width=800,
height=480,
corner_radius=20,
fg_color="#ffffff",
segmented_button_selected_color="red",
segmented_button_fg_color="black",
segmented_button_selected_hover_color="green",
segmented_button_unselected_hover_color="green")
self.tabview.pack(padx=20, pady=20)
self.tabview.add("Home")
self.tabview.add("New Recipe")
self.tabview.add("Saved Recipe")
self.tabview.tab("Home").grid_columnconfigure(0, weight=1) # configure grid of individual tabs
self.tabview.tab("New Recipe").grid_columnconfigure(0, weight=1)
self.tabview.tab("Saved Recipe").grid_columnconfigure(0, weight=1)
self.label = ctk.CTkLabel(self.tabview.tab("New Recipe"), text="Ingredient", text_color="#9933cc", anchor="w", justify="left", font=("Arial Bold", 16)).place(x=25, y=65)
self.label2 = ctk.CTkLabel(self.tabview.tab("New Recipe"), text="Int", text_color="#9933cc", anchor="w", justify="center", font=("Arial Bold", 16)).place(x=200, y=65)
self.label3 = ctk.CTkLabel(self.tabview.tab("New Recipe"), text="Unit", text_color="#9933cc", anchor="w", justify="center", font=("Arial Bold", 16)).place(x=375, y=65)
self.ingredientEntry = ctk.CTkEntry(self.tabview.tab("New Recipe"),placeholder_text="ingredient")
self.ingredientEntry.pack(ipadx=90, ipady=10)
self.ingredientEntry.place(x=25, y=100)
self.ingredientEntries = []
self.addButton = ctk.CTkButton(self.tabview.tab("New Recipe"), text="Add Ingredient", command=self.add_ingredient)
self.addButton.place(x=25, y=25)
self.saveButton = ctk.CTkButton(self.tabview.tab("New Recipe"), text="Save Recipe", command=self.save_recipe)
self.saveButton.place(x=175, y=25)
def add_ingredient(self):
newEntry = ctk.CTkEntry(self.tabview.tab("New Recipe"), placeholder_text="ingredient")
newEntry.place(x=25, y =150)
self.ingredientEntries.append(newEntry) # Add the new entry to your list
What would be my best solution for this- is there a solution with .place() rather than .pack() as I find .pack() is a lot more difficult to get elements in desired positions.
Also as a secondary issue- my add_ingredient function is supposed to add new textbox fields when the addButton is pressed, but when I use .place() I can only set the location of the first textbox generated, how would I get the subsequent textboxes to appear a set distance below the first?
Note I tagged TKinter as a lot of solutions for TKinter are transferable into Customtkinter- so if you have a solution using TKinter I may be able to convert it across.
Many Thanks! C0untV