How to use tkinter to create a graph

Project goals:

The aim for this project is to

  1. Use python programming tools & tkninter library on Raspberry PI
  2. to create a graph to randomly display a timer interrupt routine.

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
  3. Download the chartlib.py and save it in the same folder as this code.

Both of these prerequisites have been explained step-by-step in the following post:  http://www.ardiotech.com/en/install-raspbian-os-remote-connect/

Steps to create the graph:

  1. Connect to your Raspberry PI via remote desktop connection
  2. Go to Programming and open Thonny Pyton IDE
  3. Download chartlib and test_chartlib and unzip them in a directory
  4. Go to Thonny Pyton IDE Menu File and Open the file test_charrtlib.py
  5. Press the run button to run the code.

About the code:

  • In the first section, we are creating a window, defining the size and background.  Then we are adding the Exit button with its associated exit program function.
  • Then the code generates a new random number every 100 ms.  (g_value)
  • Then this random number is plotted.
  • The chart library is used to define the x and y-axis min and max values.

download:  chartlib  test_chart

 


 

 

Leave a Reply

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