0

I am creating an app in which i want display data in tabular format i created a GUI windows that displays the data properly but whenever i recall the same function or any other GUI function my GUI window Gets Resized/Rescaled to a smaller size

def tableGUIP(file):
    data = []
    header_list = []
    df = pd.read_csv(file, sep=',', engine='python', header=None)
    data = df.values.tolist()               # read everything else into a list of rows
    header_list = df.iloc[0].tolist()
    data = df[1:].values.tolist()

    layout = [
        [sg.Table(values=data,
                headings=header_list,
                display_row_numbers=False,
                auto_size_columns=True,
                row_height=20,
                num_rows=min(20, len(data)))],
                [sg.Text('Column', size =(15, 1))],
                [sg.Button("Rank"),sg.Button("Live"),sg.Button("2020"),sg.Button("Area"),sg.Button("Density"),sg.Button("Growth"),sg.Button("World %"),sg.Exit()]
                
    ]
    window = sg.Window('Table', layout, grab_anywhere=False,use_default_focus=True,keep_on_top=True,finalize=True)
    event, values = window.read()
    while True:
        if event in (None, 'Exit'):
            sortcol('Exit')
            break   
        # in ('Rank','2022 (Live)', '2020 Population', 'Area', 'Density', 'Growth Rate', 'World %'):
        if event == "Rank":
            sortcol('Rank')
            break
        elif event=="Live":
            sortcol('2022 (Live)')
            break
        elif event=="2020":
            sortcol('2020 Population')
            break
        elif event=="Area":
            sortcol('Area')
            break
        elif event=="Density":
            sortcol('Density')
            break
        elif event=="Growth":
            sortcol('Growth Rate')
            break
        elif event=="World %":
            sortcol('World %')
            break
    window.close()

This is the GUI windows after the first occurrence occurs This is the GUI windows When the first occurrence occurs

1
  • Function tableGUIP called twice and got nothing wrong if function sortcol do nothing. It looks the issue happened not in the code your provided here. Most of time it happened when you use Matplotlib.pyplot with PySimpleGUI, and the version of Matplotlib greater or equal 3.5.1.
    – Jason Yang
    Jul 20, 2022 at 11:29

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy