Replies: 1 comment 6 replies
-
@YS26908 This happens because the Window frame which is created or placed by canvas requires the from customtkinter import(
CTk,
CTkLabel,
CTkScrollableFrame
)
import re
def expand_frame(s_frame: CTkScrollableFrame):
width = height = 0
for child in s_frame.winfo_children():
child.update()
match = re.match(r"(\d+)x(\d+)\+(\d+)\+(\d+)", child.winfo_geometry())
w, h, x, y = map(int, match.groups())
width += w + x
height += h + y
# Using tcl commands because CustomTkinter does not allow to modify internal frame
s_frame.tk.call(s_frame, "configure", "-width", width, "-height", height)
if __name__ == "__main__":
app = CTk()
sf = CTkScrollableFrame(app, width=500, height=300)
sf.pack(fill="both", expand=True, padx=10, pady=10)
lab = CTkLabel(sf, text=f"Label", fg_color="black", corner_radius=10)
lab.place(x=10, y=10, anchor="nw")
lab2 = CTkLabel(sf, text=f"Label", fg_color="black", corner_radius=10)
lab2.place(x=10, y=800, anchor="nw")
expand_frame(sf)
app.mainloop() The subsequent application of I hope this is helpful to you. |
Beta Was this translation helpful? Give feedback.
-
I'm using a scrollable frame and adding frames (for rows) to which I add products gives a grid-type look. I don't know if placing isn't compatible with ctkscrollable frame or what but for some reason the rows don't appear properly at all.
Here is the code:
This is how it appears:
As can be seen, the rows are squashed at the top of the menu, I'm not too sure about this but on checking the height of the scrollable menu frame (width as well) the check returns 1. So, I tried to set the height explicitly with products_frame.configure(height=1000) and again it just refused to change and kept returning 1. If anyone has any suggestions or if you want to see anything else for context or more info please lmk. Would appreciate any help.
Beta Was this translation helpful? Give feedback.
All reactions