r/PySimpleGUI•
_Iv

Is it possible to have an element drawn inside a table cell?

For the project I am working on, I would like to use a Button element that is drawn inside a table cell. At the moment, I am trying to do something like sg.Table([[sg.B('x')]]) and it is simply drawing 'PySimpleGUI.PySimpleGUI.Button' in the cell.

​

I am wondering if there is any ability to draw elements in the text box or if there is some limitation preventing it.

​

As an alternative, I would just simulate a table with padding elements but I am hoping to take advantage of list.append() to dynamically increase the number of buttons drawn. If there is another workaround I am missing I am open to hearing too!

​

Thanks!

Posted Jan 3, 2020, 6:16 PM UTC

13
_IvOP•

I am working on a workaround involving appending to a frame layout. The below code is close but I'm running into the whole 'dynamic' window issue that tables circumvent.

import PySimpleGUI as sg

sg.theme('Reddit')

frame_list = [[sg.B('Add Button')], [sg.B('x')]]

layout = [[sg.Frame('Frame', frame_list, key='layout')]]

window = sg.Window('Table Test', layout)

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

if event is None:

break

if event == 'Add Button':

frame_list.append([sg.B('x')])

window['layout'].update('Frame', frame_list)

window.refresh()

1
MikeTheWatchGuy•

The way around "dynamic" layouts is to create elements that are hidden that are exposed as needed.

Maybe if you could describe the result you're looking for then I could make a recommendation that would be more helpful. You cannot dynamically add elements to a layout after the layout is created using the technique you're suggesting.

1
MikeTheWatchGuy•

You can't add elements to a table. You can simulate this easily enough though by using elements in a way that forms what looks like a table. There are a number of demos that show how to make tables using input element for example.

1