alejandroautalan / pygubu

A simple GUI builder for the python tkinter module
MIT License
2.04k stars 214 forks source link

It seems `ScrolledFrame` doesn't work for `place layout`. #265

Open larryw3i opened 2 years ago

larryw3i commented 2 years ago

Hello, @alejandroautalan , it seems ScrolledFrame doesn't work for place layout.
my code:

import tkinter as tk
from pygubu.widgets.scrolledframe import ScrolledFrame

root = tk.Tk()

scrolledframe =  ScrolledFrame(
    root,
    scrolltype="horizontal"
)

prev_x = 0
for i in range(100):
    label= Label(
        scrolledframe.innerframe,
        text="ABCD ")
    label.place(x=prev_x, y=0)
    prev_x += label.winfo_reqwidth()    

scrolledframe.place(x=0, y=0, height=500, width=200)

root.mainloop()

and the widget appears without scrollbar.
Screenshot from 2022-07-21 04-19-38

Regards. larryw3i

alejandroautalan commented 2 years ago

Hello @larryw3i thanks for the report. It seems that the method winfo_reqwidth is not informing correctly about the size of the frame when contains placed children widgets.

import tkinter as tk

root = tk.Tk()
root.geometry("200x500")
frame =  tk.Frame(root)

prev_x = 0
for i in range(100):
    label= tk.Label(
        frame,
        text="ABCD ")
    label.place(x=prev_x, y=0)
    #print(prev_x)
    prev_x += label.winfo_reqwidth()    
frame.place(x=0, y=0, width=200, height=500)

def print_width():
    print(f"Width: {frame.winfo_width()}")
    print(f"ReqWidth: {frame.winfo_reqwidth()}")

root.after(800, print_width)
root.mainloop()

Output:

Width: 200
ReqWidth: 1

I will investigate that and find a solution. Regards

Alejandro A

alejandroautalan commented 2 years ago

As indicated on this page, the place manager does not compute geometric propagation. Therefore to support place in the ScrolledFrame, the size of the innerframe it has to be calculated manually.

larryw3i commented 2 years ago

@alejandroautalan Ok, It looks normally, I really appreciate your help.
Screenshot from 2022-07-21 17-03-18