#9 Checkboxes: Building Modern GUIs using Python | Full Course | 2025

THE SUMMARYAI-generated

Key Concepts

  • Checkboxes in PI Visual
  • Customization of checkboxes (size, color, text, border, checkmark)
  • Event handling with on_change
  • Accessing checkbox value in Python
  • Integration with UI and backend logic
  • PV Store for code examples

Checkbox Implementation in PI Visual

Project Setup

  1. Create a new project in PI Visual, naming both the project and the Python directory "checkbox".
  2. Obtain the absolute path of the Python directory.
  3. Save the PI Visual project and link it to the Python directory to enable autosync.

Adding Checkboxes

  1. Navigate to the "inputs" section in PI Visual and select "checkboxes".
  2. Add checkboxes to the UI.
  3. Update the UI to reflect changes in the Python side.

Basic Functionality

  • Checkboxes can be clicked on the text or the checkbox area itself.
  • The state of the checkbox (checked or unchecked) can be accessed and manipulated in Python.

Customization Options

Size and Default Value

  • The size (width and height) of the checkbox can be adjusted.
  • The checked property sets the default state of the checkbox (checked or unchecked).

Text

  • The text associated with the checkbox can be customized.

Checkbox Settings

  • Check Color: The color of the checkbox when it is checked.
  • Unchecked Color: The color of the checkbox when it is unchecked.
  • Check Mark Color: The color of the check mark inside the checkbox when it is checked.
  • Spacing: The spacing between the checkbox and the text.

Border Settings

  • Border Width: The width of the border around the checkbox.
  • Border Color: The color of the border around the checkbox.

Check Mark Type

  • The check mark can be customized to be a dash, asterisk, or a custom character/emoji.
  • Emojis can be added by copying and pasting them into the check mark field.

Font Settings

  • The font family, size, weight (bold, italic), and color of the text can be customized.

Radius and Padding

  • Corner Radius: The radius of the corners of the checkbox.
  • Padding: The padding around the checkbox.

Coding and Event Handling

Attaching Events

  1. Assign a name to the checkbox in PI Visual (e.g., "accept").
  2. In the app.py file, access the checkbox using UI.page_0.checkbox_name.
  3. Attach an event handler function to the on_change event.

Event Handler Function

  • The event handler function receives the changed value (True for checked, False for unchecked) as input.
  • Example:
def do_something(value):
    print(value)

UI.page_0.accept.on_change = do_something

Using the Checkbox Value

  • The value received in the event handler can be used to trigger other actions, such as:
    • Enabling the next page
    • Displaying a popup
    • Changing the text

Example: To-Do List Application

PV Store Example

  • The video references a to-do list application available on the PV Store.
  • The to-do list demonstrates the use of checkboxes for marking tasks as complete.

Functionality

  • Users can add tasks to the list.
  • Each task has a checkbox to mark it as complete.
  • The application limits the number of incomplete tasks.

Code Access

  • The code for the to-do list application can be downloaded from the PV Store.

Notable Quotes

  • "So now the autosync is enabled and we can use it as before."
  • "So you have a lot of options that you can play around with."
  • "The coding part is very simple again."
  • "As you can see checkbox has a lot of functionality and it can open up a lot of possibilities for these projects."

Technical Terms

  • PI Visual: The visual development environment used in the video.
  • Autosync: Automatic synchronization between the PI Visual UI and the Python code.
  • PV Store: A repository for PI Visual projects and code examples.
  • on_change: An event that is triggered when the state of the checkbox changes.

Synthesis/Conclusion

The video provides a comprehensive guide to using checkboxes in PI Visual, covering everything from basic implementation to advanced customization and event handling. It demonstrates how to create and style checkboxes, access their values in Python, and integrate them into a UI. The to-do list example showcases a practical application of checkboxes in a real-world scenario. The availability of code examples on the PV Store allows viewers to quickly get started and experiment with the concepts discussed.

AI summaries can miss context or contain errors. Check important details against the original video.

Go a little deeper.

Have a question about this video? Load its transcript to open the video chat.