#10 Sliders: Building Modern GUIs using Python | Full Course | 2025

By Murtaza's Workshop - Robotics and AI

TechnologyBusinessStartup
Share:

Key Concepts

  • PI Visual: A software or platform used for creating visual interfaces.
  • Sliders: Interactive UI elements that allow users to select a value from a range by moving a knob along a track.
  • Bounding Box: The rectangular area that encloses a UI element, defining its position and size.
  • Track: The background bar of a slider.
  • Knob: The movable part of a slider that the user interacts with.
  • Attach Events: A mechanism in PI Visual to link UI element changes to specific functions or code.
  • On Change Event: A specific event triggered when the value of a UI element, like a slider, is modified.

Introduction to Sliders in PI Visual

The video demonstrates how to use sliders within the PI Visual environment. The process begins with creating a new project named "slider" and navigating to the "Inputs" section, where the "sliders" option is available. Users can then add various slider designs to their project.

Interacting with Sliders

  • Settings Access: To access the settings of a slider, one needs to click on the side of its bounding box.
  • Value Adjustment: The actual value of the slider is changed by clicking and moving the knob.
  • Click Interaction: Users can click on any point within the slider's bounding region to directly set the value, not just on the knob itself.

Project Setup and Linking

Before diving into technical details, the video emphasizes linking the PI Visual project to a local folder. This involves creating a new directory (e.g., "slider"), copying its path reference, and pasting it into PI Visual to establish a connection. Updating the project ensures file transfer, allowing the slider to be run and tested.

Slider Components and Customization

A slider is composed of two main parts: the track and the knob.

Track Settings:

  • Track Color: The color of the background bar can be changed (e.g., from light purple to dark green).
  • Track Height: The thickness of the track can be adjusted.
  • Fill Color: The color of the area indicating the current value on the track can be modified (e.g., to red).
  • Track Border: A border can be added to the track by adjusting the border thickness and selecting a color (e.g., darker green).
  • Corner Radius: The corners of the track can be rounded by adjusting the corner radius.

Knob Settings:

  • Width and Height: The dimensions of the knob can be increased or decreased.
  • Knob Color: The color of the knob can be customized (e.g., to orange).
  • Hover Color: The color of the knob when the mouse hovers over it can be set (e.g., to dark orange).
  • Knob Border: A border can be added to the knob, with adjustable thickness and color (e.g., red).
  • Corner Radius: The corners of the knob can also be rounded.

Displaying Numerical Values

A key feature discussed is the ability to display the numerical value of the slider.

  • Enabling Text Display: This is done by clicking on the "text" option within the slider settings.
  • Text Adjustment: The height of the text can be adjusted for better visibility.
  • Font Customization: Users can change the font, size, make it bold or italic, and select the font color (e.g., red).

Slider Configuration Parameters

Beyond visual customization, sliders have functional parameters:

  • Minimum Value: The lowest possible value the slider can represent (e.g., 50).
  • Current Value: The initial or default value of the slider (e.g., 100).
  • Maximum Value: The highest possible value the slider can represent (e.g., 200).
  • Positioning: Sliders can be pushed back or brought forward in the UI layer.
  • Opacity: The transparency of the slider can be adjusted.

Coding with Sliders in PI Visual

The video transitions to explaining how to integrate sliders into code using PyCharm.

Attaching Events:

  1. Identify Slider Name: The first step is to identify the unique name of the slider element in the PI Visual code (e.g., slider_0).
  2. Event Binding: Use the on_change event to trigger a function whenever the slider's value changes. This is done by writing ui.page_0.slider_0.on_change = do_something.
  3. Define Callback Function: Create a Python function (e.g., do_something) that will be executed when the on_change event fires. This function receives the current value of the slider as an argument.
  4. Utilize Slider Value: Inside the callback function, the value can be printed to the console for debugging or used to perform other actions within the application.

Example Code Snippet (Conceptual):

# In PI Visual UI code
# ... slider_0 definition ...

# In your Python logic file
def do_something(value):
    print(f"Slider value changed to: {value}")

# Attaching the event
ui.page_0.slider_0.on_change = do_something

Conclusion and Further Possibilities

The video concludes by highlighting the extensive customization options available for sliders in PI Visual, which opens up numerous possibilities for creating interactive and dynamic user interfaces. The presenter encourages viewers to ask questions in the comments section.

Chat with this Video

AI-Powered

Hi! I can answer questions about this video "#10 Sliders: Building Modern GUIs using Python | Full Course | 2025". What would you like to know?

Chat is based on the transcript of this video and may not be 100% accurate.

Related Videos

Ready to summarize another video?

Summarize YouTube Video