Exploring Containers and Layouts in PySimpleGUI 2020: Part 9 (Columns, Frames, Tabs, Panes)

Posted by


In this tutorial, we will discuss about Containers in PySimpleGUI, a Python GUI framework. Containers are used to hold and organize different elements within a GUI application. PySimpleGUI offers various types of containers such as Columns, Frames, Tabs, and Panes to create layouts within layouts.

  1. Columns:
    Columns are used to divide the GUI window into multiple sections horizontally. Each section can contain different elements such as buttons, text boxes, labels, etc. To create a column, we can use the sg.Column function and specify the list of elements that need to be placed within the column.
import PySimpleGUI as sg

layout = [
    [sg.Text('Enter your name:')],
    [sg.InputText(key='name')],
    [sg.Button('Submit')]
]

column = sg.Column(layout)

window = sg.Window('Column Example', [[column]])
  1. Frames:
    Frames are used to group related elements within a GUI window. Frames create a border around the elements they contain, making them visually distinct from other elements. To create a frame, we can use the sg.Frame function and specify the list of elements that need to be placed within the frame.
import PySimpleGUI as sg

layout = [
    [sg.Frame('Personal Information', [
        [sg.Text('Enter your name:')],
        [sg.InputText(key='name')],
        [sg.Text('Enter your age:')],
        [sg.InputText(key='age')],
    ])],
    [sg.Button('Submit')]
]

window = sg.Window('Frame Example', layout)
  1. Tabs:
    Tabs are used to organize different sections of a GUI application into separate tabs. Each tab contains a unique set of elements. To create tabs, we can use the sg.Tab function and specify the list of elements that need to be placed within each tab.
import PySimpleGUI as sg

tab1_layout = [
    [sg.Text('Tab 1')],
]

tab2_layout = [
    [sg.Text('Tab 2')],
]

layout = [
    [sg.TabGroup([
        [sg.Tab('Tab 1', tab1_layout)],
        [sg.Tab('Tab 2', tab2_layout)],
    ])],
    [sg.Button('Submit')]
]

window = sg.Window('Tabs Example', layout)
  1. Panes:
    Panes are used to create resizable sections within a GUI window. Panes can be resized by dragging the edges of the pane. To create a pane, we can use the sg.Paned function and specify the list of elements that need to be placed within the pane.
import PySimpleGUI as sg

layout = [
    [sg.Paned([
        [sg.Text('Pane 1')],
        [sg.Text('Pane 2')],
    ])],
    [sg.Button('Submit')]
]

window = sg.Window('Panes Example', layout)

In this tutorial, we have discussed about different types of containers available in PySimpleGUI such as Columns, Frames, Tabs, and Panes. These containers can be used to create layouts within layouts, organize elements within a GUI window, and improve the overall user experience. Make sure to experiment with different container types to create visually appealing and user-friendly GUI applications.

0 0 votes
Article Rating

Leave a Reply

7 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@ianfrancis3605
3 hours ago

Thanks this saved me a lot of time.

@georgesal-habre103
3 hours ago

Hello,
is it possible to hide the tab buttons (Tab 1, 2, 3 Tab) that are on top and use buttons (images) placed elsewhere in their place to switch between tabs?

I would like to make a more modern layout using circular icons on the left. A bit like a list of servers on Discord.

@jorgegil13283
3 hours ago

Hi Mike,

I am using columns to simply play with the visibility of the elements (visible=True or False). However if i use two different layouts one of them just fall down at the end of the first layout even if I set layout 1 in visible=False.

I have checked the demos but even into them I just found one which I modified but the same behaviour appears.

Any suggestion about that? Always willing to receive your comments 😊

@scrapyboy7762
3 hours ago

MIke you are a Champion, very thanks you.

@XeneiFana
3 hours ago

Hey, thank you for the great work on PySimpleGUI. I think it's awesome!

Not to get too picky, but why did you name the vSeperator that way, instead of vSeparator?

@PySimpleGUI
3 hours ago

Dear YouTube viewers…. Is the audio quality significantly different / worth it?

The new microphone setup makes it difficult to type and I made the mistake of trying to type too much in this particular lesson anyway (watching me fumble around on the keyboard does not help you program better). So the combination was particularly bad in this case.

The next lesson, #10, also used this better microphone setup but I typed less. Locally, it sounds better, but I have no idea for the rest of you if it matters or sounds any better. Opinions are welcomed.

@chrischambers5292
3 hours ago

I was spending way too much time trying to align my elements with padding before this…. SO helpful.
Question though:

Is there any way to have a text element where only one word is a different color/font?

7
0
Would love your thoughts, please comment.x
()
x