PySimpleGUI - Frame Element



The Frame element is a container object that holds on or more elements of other types. It helps in organizing the GUI elements in a logical manner. For example, multiple radio button elements belonging to same group are put inside a frame. It forms a rectangular border around the elements. The frame can have a label and can be placed as per requirement.

PySimpleGUI.Frame(title, layout, title_location)

The title parameter is the text that is displayed as the Frame's "label" or title. The Frame object can be seen as a child layout of the layout of the main window. It may also be a list of list of elements.

The "title_location" is an enumerated string that decides the position of the label to the frame. The predefined values are TOP, BOTTOM, LEFT, RIGHT, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, and BOTTOM_RIGHT.

The Frame object is not normally used as an event listener. Still, when clicked on the area of frame, its title can be updated although this feature is rarely used.

The following code is the same that was used as the example of checkbox. Here, the three radio buttons for choosing the Faculty and the subjects in the chosen faculty as checkboxes are put in separate frames.

import PySimpleGUI as psg
psg.set_options(font=("Arial Bold", 14))
l1 = psg.Text("Enter Name")
l2 = psg.Text("Faculty")
l3 = psg.Text("Subjects")
l4 = psg.Text("Category")
l5 = psg.Multiline(" ", expand_x=True, key='-OUT-',  expand_y=True, justification='left')
t1 = psg.Input("", key='-NM-')
rb = []
rb.append(psg.Radio("Arts", "faculty", key='arts',  enable_events=True, default=True))
rb.append(psg.Radio("Commerce", "faculty", key='comm', enable_events=True))
rb.append(psg.Radio("Science", "faculty", key='sci', enable_events=True))
cb = []
cb.append(psg.Checkbox("History", key='s1'))
cb.append(psg.Checkbox("Sociology", key='s2'))
cb.append(psg.Checkbox("Economics", key='s3'))
b1 = psg.Button("OK")
b2 = psg.Button("Exit")
rlo = psg.Frame("Faculty", [rb], title_color='blue')
clo = psg.Frame("Subjects", [cb], title_color='blue')
layout = [[l1, t1], [rlo], [clo], [b1, l5, b2]]
window = psg.Window('Frame Example', layout, size=(715, 200))

The output of the program is shown below −

Frame Element
pysimplegui_element_class.htm
Advertisements