PySimpleGUI - Column Element



The Column element is also a container widget. It is very useful if you want to design the GUI window elements represented in one or more vertical columns. Just as a window, the Column area places the other PySimpleGUI elements in a layout consisting of list of lists.

A Column layout is similar to a Frame. However, the Column doesn’t have border or title as the Frame. But it is very effective when you want to place group of elements side by side.

The mandatory parameter to be passed to the Column constructor is layout as list of lists, each inner list being a row of elements.

Other parameters may be given as −

PySimpleGUI.Column(layout, size, scrollable,
vertical_scroll_only, element_justification)

Where,

  • layout − Layout that will be shown in the Column container

  • size − (width, height) size in pixels

  • Scrollable − if True then scrollbars will be added to the column

  • vertical_scroll_only − if True then no horizontal scrollbar will be shown

  • element_justification − All elements inside the Column will have this justification 'left', 'right', or 'center'

One of the important methods defined in the Column class is contents_changed(). If the scrollable property is enabled for the Column, and the layout changes by making some elements visible or invisible, the new scrollable area is computed when this method is called.

Although the container elements like Column normally are not event listeners, its visible property may be dynamically updated.

The following code shows how you can use the Column element. The main layout’s upper row has a Text and Input element. The last row has "Ok" and "Cancel" buttons. The middle row has two columns, each having input elements for entering the correspondence and permanent address. Their element layouts are stored as col1 and col2. These are used to declare two Column objects and placed in the list for middle row of the main layout.

import PySimpleGUI as psg
psg.set_options(font=("Arial Bold",10))
l=psg.Text("Enter Name")
l1=psg.Text("Address for Correspondence")
l2=psg.Text("Permanent Address")
t=psg.Input("", key='-NM-')
a11=psg.Input(key='-a11-')
a12=psg.Input(key='-a12-')
a13=psg.Input(key='-a13-')
col1=[[l1],[a11], [a12], [a13]]
a21=psg.Input(key='-a21-')
a22=psg.Input(key='-a22-')
a23=psg.Input(key='-a23-')
col2=[[l2],[a21], [a22], [a23]]
layout=[[l,t],[psg.Column(col1), psg.Column(col2)], [psg.OK(), psg.Cancel()]]
window = psg.Window('Column Example', layout, size=(715,200))
while True:
   event, values = window.read()
   print (event, values)
   if event in (psg.WIN_CLOSED, 'Exit'):
      break
window.close()

It will produce the following output window −

Column Element
pysimplegui_element_class.htm
Advertisements