2

I am tring to construct a GUi that would display two columns: one column would have all the input fields and listboxes, the second column would display some data from pandas dataframe.

I thought it would be a good idea to do this using Frames, but I am running into an error when trying to create a Frame:

layout = [sg.Frame('Input data',[[
          sg.Text('Input:'),      
          sg.Input(do_not_clear=False),      
          sg.Button('Read'), sg.Exit(),
          sg.Text('Alternatives:'),
          sg.Listbox(values=('alternatives...', ''), size=(30, 2), key='_LISTBOX_')]])] 

Result:

TypeError: AddRow() argument after * must be an iterable, not Frame

How to fix this?

I am thinking if it is possible to define columns first, using Frame, and then putting the columns into the definition of layout?

milka1117
  • 521
  • 4
  • 8
  • 17

1 Answers1

5

You have to use [[ ]]

layout = [[

]]

External [ ] means all data, internal [ ] means first row - even if you need only one row.


Working example:

import PySimpleGUI as sg

layout = [[
    sg.Frame('Input data',[[
          sg.Text('Input:'),      
          sg.Input(do_not_clear=False),      
          sg.Button('Read'), sg.Exit(),
          sg.Text('Alternatives:'),
          sg.Listbox(values=('alternatives...', ''), size=(30, 2), key='_LISTBOX_')
    ]])
]]

window = sg.Window('App', layout)
event, values = window.Read()
window.Close()
furas
  • 134,197
  • 12
  • 106
  • 148
  • 1
    Spot on correct! All layouts in PySimpleGUI are a "list of lists of elements". That's true for all of the "Container Elements" including Column, Frame, etc. They all take that same [ [ ] ] format. – Mike from PSG Jul 17 '19 at 13:23
  • @MikeyB it almost the same - I called it "list of rows of elements" :) – furas Jul 17 '19 at 13:37
  • 1
    Correct you are. List of rows of Elements is exactly what they are. – Mike from PSG Jul 17 '19 at 16:08