To do list using generated layout
Generated Layouts - To Do List Program
This program demonstrates how you can a Python "List Comprehension" to create
a GUI layout. The layout is created in 3 steps.
1. A title line
2. The list of checkboxes and descriptions
3. The buttons
That is the layout that these 3 lines of code create
layout = [[Text('My To Do List', font='Helvetica 15')]]
layout += [[Text(f'{i}. '), CBox('', key=f'-CB{i}-'), Input(k=f'-IN{i}-')] for i in range(1,6)]
layout += [[Button('Save'), Button('Load'), Button('Exit')]]
This program is a little different in that it imports the individual objects being used. Typically the import you'll find in most PySimpleGUI programs is
The result of importing each object is that you do not need the sg.
before each function call, thus making the code even more compact. The layout looks cleaner as well.
However, there are a few drawbacks. One is being able to easily spot calls to the PySimpleGUI package. Another is code completion. If you type sg.
(control+SPACE) in an IDE, it will show you a list of choices from the PySimpleGUI pacakge that are available to you.
It's being presented simply as another way of doing things. You'll find the other demos use
To Do List using "normal" import (import PySimpleGUI as sg
)
In this version, the typical import statement is used. The program is identical to the one above, but you'll notice that each element and PySimpleGUI object now has sg.
in front of it. Nearly all demo programs use this import convention and users have adopted it as well. It's a standard of sorts at this point.