label = customtkinter.CTkLabel(master=frame, text="Username: ")
label.pack(padx=(10, 5), pady=10, side=customtkinter.TOP, anchor=customtkinter.W)
entry1 = customtkinter.CTkEntry(master=frame)
entry1.pack(padx=(0, 10), pady=10, side=customtkinter.TOP, expand=True, fill="x")
I've tried messing around with the side and anchor, but can't seem to get it to work.
Using customtkinter
in Python, how can I make these 2 elements go on the same row?
CodePudding user response:
Try this way. I've used grid
geometry manager instead of pack
.
label = customtkinter.CTkLabel(master=frame, text="Username: ")
label.grid(row=0, column=0, padx=(10, 5), pady=10, sticky=customtkinter.W)
entry1 = customtkinter.CTkEntry(master=frame)
entry1.grid(row=0, column=1, padx=(0, 10), pady=10, sticky="ew")
CodePudding user response:
- Switched from .pack ---> .grid
- Used columnconfigure method to add weight to columns
[Final Result:] https://i.stack.imgur.com/g6Gzf.png
Code:
import customtkinter
customtkinter.set_appearance_mode("dark")
customtkinter.set_default_color_theme("dark-blue")
root = customtkinter.CTk()
root.geometry("650x175")
root.title("Bazaar Bot - Login")
root.columnconfigure(0, weight=1)
root.columnconfigure(1, weight=50)
root.resizable(False, False)
#Username
label = customtkinter.CTkLabel(root, text="Username: ")
label.grid(row=0, column=0, padx=(15, 0), pady=10, sticky=customtkinter.W)
entry1 = customtkinter.CTkEntry(root)
entry1.grid(row=0, column=1, padx=(0, 10), pady=10, sticky="ew")
#Password
label = customtkinter.CTkLabel(root, text="Password: ")
label.grid(row=1, column=0, padx=(15, 0), pady=10, sticky=customtkinter.W)
entry1 = customtkinter.CTkEntry(root)
entry1.grid(row=1, column=1, padx=(0, 10), pady=10, sticky="ew")
Thanks, @Gihan