Search code examples
pythonuser-interfacetkintercustomtkinter

How to make two frames not align to center in y-axis using the grid() method in customtkinter


I want the main frame to be at the y-coordinate of the main frame (using the grid method), but it doesn't work. Can anyone help me?

I want the optFrame to be at the position of the red square.

import customtkinter as ctk

#Tema
ctk.set_default_color_theme("minimalistTheme.json")

#Main window
timedoro = ctk.CTk()
timedoro.geometry("1500x750")
timedoro.title("Time-Doro!")
timedoro.iconbitmap("tdicon.ico")
timedoro.resizable(False, False)

#Options Frame
optFrame = ctk.CTkFrame(timedoro, width=100, height=100, corner_radius=6)
optFrame.grid(row=0, column=1, padx="25")

#Mainloop
timedoro.mainloop()

Output

I tried to fix the error by changing the size, but it doesn't work.


Solution

  • Both frames are on the same row. By default, grid will center a widget within its cell. If you want the frame on the left to be aligned to the top of the row you need to specify that when calling grid using the sticky attribute. It takes the first letter of compass directions as an argument (n=north, s=south, ne=northeast, etc).

    optFrame.grid(row=0, column=1, padx=10, sticky="n")
    #                                     ^^^^^^^^^^^^