TomSchimansky / CustomTkinter

A modern and customizable python UI-library based on Tkinter
MIT License
11.33k stars 1.07k forks source link

OptionMenu cut off #2397

Closed KorryKatti closed 5 months ago

KorryKatti commented 5 months ago

image

The option menu at the right most is cut off from the display even at full screen , how do i fix it

relevant part of the code

# Create a frame inside the main window for organizing widgets
frame = ctk.CTkFrame(app)
frame.pack(fill=ctk.BOTH, expand=True, padx=11, pady=10)  # Pack the frame to fill the window

# Create the optionmenu widget
optionmenu = ctk.CTkOptionMenu(frame, values=["Home", "Client Update", "Quit"],
                                         command=optionmenu_callback)
optionmenu.grid(row=0, column=0, padx=2, pady=0, sticky=ctk.W)  # Align to the west (left)

# Create the library menu widget
libmenu = ctk.CTkOptionMenu(frame, values=["Library", "Apps Update"],
                                         command=libmenu_callback)
libmenu.grid(row=0, column=1, padx=0, pady=0, sticky=ctk.W)  # Align to the west (left)

# Create the Commmunity Widget
commenu = ctk.CTkOptionMenu(frame, values=["Community", "Image Board", "Thunder Halls"],
                                         command=commenu_callback)
commenu.grid(row=0, column=2, padx=0, pady=0, sticky=ctk.W)  # Align to the west (left)

# Create DevBlogs Widget
devmenu = ctk.CTkOptionMenu(frame,values=["DevBlog", "Changelogs"],
                                         command=devmenu_callback)
devmenu.grid(row=0, column=3, padx=0, pady=0, sticky=ctk.W)  # Align to the west (left)

# Create the theme selector
thememenu = ctk.CTkOptionMenu(frame,values=["Default","Orange","Green","Coffee","Violet","Blue","Carrot","Marsh","Metal","Pink","Red","Rose","Sky","Yellow"], command=theme_set)
thememenu.grid(row=0, column=4, padx=0, pady=0, sticky=ctk.W)  # Align to the west

the menu i am talking about is the thememenu

KorryKatti commented 5 months ago

i tried putting padx to 0 in an attempt to reduce their distances but to no gain

rigvedmaanas commented 5 months ago

Hi @KorryKatti,

This was the result of your code in my machine. It didn't give me the same result. Screenshot 2024-05-02 at 6 42 45 PM

I changed the code to the following. pack is used display the optionmenu.

frame = ctk.CTkFrame(app)
frame.pack(fill=ctk.BOTH, expand=True, padx=11, pady=10)  # Pack the frame to fill the window

# Create the optionmenu widget
optionmenu = ctk.CTkOptionMenu(frame, values=["Home", "Client Update", "Quit"],
                                         command=optionmenu_callback)
optionmenu.pack(expand=True, pady=10, padx=10, side="left")

# Create the library menu widget
libmenu = ctk.CTkOptionMenu(frame, values=["Library", "Apps Update"],
                                         command=libmenu_callback)
libmenu.pack(expand=True, pady=10, padx=10, side="left")

# Create the Commmunity Widget
commenu = ctk.CTkOptionMenu(frame, values=["Community", "Image Board", "Thunder Halls"],
                                         command=commenu_callback)
commenu.pack(expand=True, pady=10, padx=10, side="left")

# Create DevBlogs Widget
devmenu = ctk.CTkOptionMenu(frame,values=["DevBlog", "Changelogs"],
                                         command=devmenu_callback)
devmenu.pack(expand=True, pady=10, padx=10, side="left")

# Create the theme selector
thememenu = ctk.CTkOptionMenu(frame,values=["Default","Orange","Green","Coffee","Violet","Blue","Carrot","Marsh","Metal","Pink","Red","Rose","Sky","Yellow"], command=theme_set)
thememenu.pack(expand=True, pady=10, padx=10, side="left")

Result: Screenshot 2024-05-02 at 6 46 39 PM

Hope this helps

KorryKatti commented 5 months ago

I have this code ahead of the previous one too

also i can't use pack because it causes this error

File "/usr/lib/python3.11/tkinter/init.py", line 2568, in grid_configure self.tk.call( _tkinter.TclError: cannot use geometry manager grid inside .!ctkframe which already has slaves managed by pack

frame = ctk.CTkFrame(app)
frame.pack(fill=ctk.BOTH, expand=True, padx=11, pady=10)  # Pack the frame to fill the window

# Create the optionmenu widget
optionmenu = ctk.CTkOptionMenu(frame, values=["Home", "Client Update", "Quit"],
                                         command=optionmenu_callback)
optionmenu.grid(row=0, column=0, padx=2, pady=0, sticky=ctk.W)  # Align to the west (left)

# Create the library menu widget
libmenu = ctk.CTkOptionMenu(frame, values=["Library", "Apps Update"],
                                         command=libmenu_callback)
libmenu.grid(row=0, column=1, padx=0, pady=0, sticky=ctk.W)  # Align to the west (left)

# Create the Commmunity Widget
commenu = ctk.CTkOptionMenu(frame, values=["Community", "Image Board", "Thunder Halls"],
                                         command=commenu_callback)
commenu.grid(row=0, column=2, padx=0, pady=0, sticky=ctk.W)  # Align to the west (left)

# Create DevBlogs Widget
devmenu = ctk.CTkOptionMenu(frame,values=["Dev Blog", "Changelogs"],
                                         command=devmenu_callback)
devmenu.grid(row=0, column=3, padx=0, pady=0, sticky=ctk.W)  # Align to the west (left)

# Create the theme selector
thememenu = ctk.CTkOptionMenu(frame,values=["Default","Orange","Green","Coffee","Violet","Blue","Carrot","Marsh","Metal","Pink","Red","Rose","Sky","Yellow","FlipperZero","hacked"], command=theme_set)
thememenu.grid(row=0, column=4, padx=0, pady=0, sticky=ctk.W)  # Align to the west

# Create a scrollable frame inside the existing frame to display contents
scrollable_frame = ctk.CTkScrollableFrame(frame, width=1024, height=576, corner_radius=0, fg_color="transparent")
scrollable_frame.grid(row=2, column=0, columnspan=4, sticky="nsew")

# Add widgets to the scrollable frame
create_labels() 
KorryKatti commented 5 months ago

my screens dimensions are 1366x768 btw if it helps

i will try changing the grids in the code to pack changing the grid to pack , is causing the scrollable frame to move towards right and the menus on left , which is not desired

rigvedmaanas commented 5 months ago

You could change the hierarchy to something like this.

- MainFrame - (pack or grid which is suitable for your app) 
      - frame - (pack)
          - optionmenu - (pack)
          - libmenu - (pack)
          - commenu - (pack)
          - devmenu - (pack)
          - thememenu - (pack)
      - scrollable_frame - (pack)

Example Code:

mainframe = CTkFrame(master=root)
mainframe.pack_propagate(False)
mainframe.pack(expand=True, fill="both")

frame = CTkFrame(master=mainframe, width=200)
frame.pack(fill="x")

optionmenu = CTkOptionMenu(master=frame, values=['Home', 'Client Update', 'Quit'])
optionmenu.pack(pady=(10, 10), expand=True, side="left")

libmenu = CTkOptionMenu(master=frame, values=["Library", "Apps Update"])
libmenu.pack(pady=(10, 10), expand=True, side="left")

commenu = CTkOptionMenu(master=frame, values=['Community', 'Image Board', 'Thunder Halls'])
commenu.pack(pady=(10, 10), expand=True, side="left")

devmenu = CTkOptionMenu(master=frame, values=["Dev Blogs", "Changelogs"])
devmenu.pack(pady=(10, 10), expand=True, side="left")

thememenu = CTkOptionMenu(master=frame, values=["Default","Orange","Green","Coffee","Violet","Blue","Carrot","Marsh","Metal","Pink","Red","Rose","Sky","Yellow","FlipperZero","hacked"])
thememenu.pack(pady=(10, 10), expand=True, side="left")

scrollable_frame = CTkScrollableFrame(master=mainframe, corner_radius=0, fg_color="transparent")
scrollable_frame.pack(expand=True, fill="both")

Hope This Helps

KorryKatti commented 5 months ago

Thanks it works now , also just in case , if i decide to add any widget in the future i will be using pack instead of grid right ?

rigvedmaanas commented 5 months ago

Thanks it works now , also just in case , if i decide to add any widget in the future i will be using pack instead of grid right ?

If you used pack for mainframe then you can only use pack for other widgets with the same parent as that of the mainframe. If you used grid for mainframe then you can only use grid for other widgets with the same parent as that of the mainframe. But you can use pack or grid inside scrollable_frame

KorryKatti commented 5 months ago

alright thanks , have a nice day