How to use Python to display a rotary slider

Project Goals

The goal of this project is to use python to create a rotary slider using Tkinter.  A rotary slider is used as an input tool – similar to a slider.  Whereas a gauge is used as a tool to display a number, a rotary slider is used to capture a number.  For example, if you wanted to modify the temperature of the room, you could either provide a numerical value to your computer or specify a point on the barometer to indicate the desired value.

Prerequisites

Prerequisite for this project are:

  1. You have setup Raspbian OS on your Raspberry PI.
  2. Knowledge to establish a remote desktop connection to your Raspberry PI

Steps:

  1. Create a new file on Thonny Python IDE and paste the code shown below.
  2. Run the code.
  3. Test the rotary slider by moving your mouse across the orange or red arch.

About the code:

  • In the first part of the code, we are creating a window and defining the background and its dimensions.  We also create an Exit button.
  • Then we create a dial using the tk.create_polygon function.
  • Then we create two arcs in two colors with the tags ‘arc1’ and ‘arc2’.
  • Then we bind mouse motion and mouse click for these tags (c.tag_bind).
  • Whenever you click on the arc and move the dial, the angle is calculated.  The X/Y coordinates of the position are displayed below the rotary slider.

Leave a Reply

Your email address will not be published. Required fields are marked *