Coder Social home page Coder Social logo

Comments (7)

jason990420 avatar jason990420 commented on July 20, 2024

It looks like that it is same as the issue #6766, or #5770 (comment)

I reduce your code and make it executable as following.

import PySimpleGUI as sg

sg.theme("DarkBlue")

engines = ["Google", "Bing", "Perplexity.ai", "You.com", "Yep.com", "Openverse"]
result_layout = []
for i in engines:
    candidate_result_layout = [[sg.Text(f'Post: {i}')]]
    for j in range(3):
        vote_text = sg.Text(f'{j} Vote)')
        candidate_result_layout += [[vote_text], [sg.ProgressBar(j, size=(j, 25), bar_color=('#4E46B4', '#4E46B4'))]]
    result_layout.append([sg.Column(candidate_result_layout, expand_x=True, size=(100, 130), background_color='#FFFFFF')])
layout = [[sg.Column(result_layout, expand_y=True, expand_x=True, scrollable=True, vertical_scroll_only=True, key="COLUMN")]]
window = sg.Window(f'Results', layout, resizable=True, finalize=True)

window.set_size((550, 200))
window.refresh()
window.move_to_center()

while True:
    event, values = window.read()

    if event==sg.WIN_CLOSED:
        break

window.close()

image

After the workaround applied

import PySimpleGUI as sg

def configure_canvas(event, canvas, frame_id):
    canvas.itemconfig(frame_id, width=canvas.winfo_width())

def configure_frame(event, canvas):
    canvas.configure(scrollregion=canvas.bbox("all"))

sg.theme("DarkBlue")

engines = ["Google", "Bing", "Perplexity.ai", "You.com", "Yep.com", "Openverse"]
result_layout = []
for i in engines:
    candidate_result_layout = [[sg.Text(f'Post: {i}')]]
    for j in range(3):
        vote_text = sg.Text(f'{j} Vote)')
        candidate_result_layout += [[vote_text], [sg.ProgressBar(j, size=(j, 25), bar_color=('#4E46B4', '#4E46B4'))]]
    result_layout.append([sg.Column(candidate_result_layout, expand_x=True, size=(100, 130), background_color='#FFFFFF')])
layout = [[sg.Column(result_layout, expand_y=True, expand_x=True, scrollable=True, vertical_scroll_only=True, key="COLUMN")]]
window = sg.Window(f'Results', layout, resizable=True, finalize=True)

column = window['COLUMN'].widget
frame_id, frame, canvas = column.frame_id, column.TKFrame, column.canvas
canvas.bind("<Configure>", lambda event, canvas=canvas, frame_id=frame_id:configure_canvas(event, canvas, frame_id))
frame.bind("<Configure>", lambda event, canvas=canvas:configure_frame(event, canvas))
window.set_size((550, 200))
window.refresh()
window.move_to_center()

while True:
    event, values = window.read()

    if event==sg.WIN_CLOSED:
        break

window.close()

image

from pysimplegui.

raghavsrvt avatar raghavsrvt commented on July 20, 2024

Thanks for the solution, could you please explain the code as I am unable to understand and also why does this problem occur?

from pysimplegui.

raghavsrvt avatar raghavsrvt commented on July 20, 2024

I got error NoneType object has no attribute frame_id
The code-

show_results_window = sg.Window(f'{results_window[result_event].get()} Results',[[sg.Column(result_layout,expand_y=True,expand_x=True,scrollable=True,vertical_scroll_only=True, key='result_container')]],size=(550,500),resizable=True,modal=True)
                
                # Code to fix columns in result_layout not expanding
                column = show_results_window['result_container'].widget
                frame_id, frame, canvas = column.frame_id, column.TKFrame, column.canvas
                canvas.bind("<Configure>", lambda event, canvas=canvas, frame_id=frame_id:configure_canvas(event, canvas, frame_id))
                frame.bind("<Configure>", lambda event, canvas=canvas:configure_frame(event, canvas))
                show_results_window.set_size((550, 200))
                show_results_window.refresh()
                show_results_window.move_to_center()

from pysimplegui.

jason990420 avatar jason990420 commented on July 20, 2024

AttributeError: 'NoneType' object has no attribute 'frame_id'

One extra option missed in your sg.Window, finalize=True.

Why element inside a scrollable Column not expanded ?

It is caused by that the scrollable Column is built with the tkinter Canvas widget, and the child elements/widgets are created inside the window which is on the canvas and no expand function.
So we need to adjust the size of the Canvas and the window/frame by ourself when related GUI configured event happened.

from pysimplegui.

raghavsrvt avatar raghavsrvt commented on July 20, 2024

I again got this error, (PSG 4.61.0.206)
image

from pysimplegui.

jason990420 avatar jason990420 commented on July 20, 2024

Maybe you forgot those two functions defined in the beginning

import PySimpleGUI as sg

def configure_canvas(event, canvas, frame_id):
    canvas.itemconfig(frame_id, width=canvas.winfo_width())

def configure_frame(event, canvas):
    canvas.configure(scrollregion=canvas.bbox("all"))

from pysimplegui.

raghavsrvt avatar raghavsrvt commented on July 20, 2024

Oh yes, sorry that I disturbed you because of my silly mistake.

from pysimplegui.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.