Get Started With Raspberry PI GUI PDF
Get Started With Raspberry PI GUI PDF
by Ahmed Nouira
So you have a Raspberry Pi and a cool idea, but how do you make it as easy as a smartphone for your user to
interact with?
Building a Graphical User Interface (GUI) is actually quite easy, and with some patience you can produce
amazing projects.
One of the most powerful tools that Raspberry Pi A powerful library for developing graphic user
provides over other micros, is the rapid rate and ease interface (GUI) applications, on the Raspberry Pi
you can create a Graphical User Interface (GUI) for where makers are concerned.
your project.
Tkinter is probably the most commonly used with
One way to achieve this , specialty if you have a full Python, and plenty of resources exist on the internet.
touchscreen (or a standard screen and input device
such as a mouse),it became amazing!
To run our Tkinter GUI Applications. we can also use any other operating system that have python installed.
Raspbian comes with both Python 2, Python 3 and the Tkinter library installed.
To check which version you have installed, from the terminal run:
python3 --version
Create a new file called app.py and enter the base code shown below :
#!/usr/bin/python
from tkinter import * # imports the Tkinter lib
root = Tk() # create the root object
root.wm_title("Hello World") # sets title of the window
root.mainloop() # starts the GUI loop
If you’re not using an IDE, run the following command in a terminal from the directory containing your Python
code to run the program.
python3 app.py
Background colour
root.configure(bg="black") # change the background colour to "black"
or
Window dimensions
root.geometry("800x480") # specify the window dimension
or
Keep in mind that you will get stuck in full-screen mode if you don’t create a way to exit.
Tkinter includes many different widgets to help you create the most appropriate user interface. Widgets you can
use include:
• text box
• buttons
• check button
• slider
• list box
• radio button
•etc..
Now we can add some widgets such as text, buttons and inputs.
Adding Widgets
Labels
Before it is visible in the window though, we need to set its position. We will use grid positioning.
Entry Input
Buttons
Now we have a simple form, however clicking on the button does not do anything!!
We will explore how to setup an event on the buttons widget and bind it to a function which executes when clicked.
For this purpose we will update label_1 to display "Hello + the text entered in the input". When you select the
submit button.
Download
https://www.instructables.com/ORIG/FQ4/Y04T/JOIXY03R/FQ4Y04TJOIXY03R.py
…
So far we see how to add button to the window and add logic to it in order to perform action.
Now, we will change the code a little bit. So we are going to create a form and add two buttons to it. One to turn
the LED on/off, and the other to exit the program.
Note : Make sure you have updated your Raspberry before starting, and that you have the GPIO library install,
Open the command window and enter the following
the GPIO library install. Open the command window and enter the following:
The Build:
Parts Required:
1 x Raspberry Pi 3
1 x LED
1 x 330 Resistor
Pay attention to the LED orientation and the pin where connected (GPIO23).
Step 8: Conclusion
myYouTube
https://www.youtube.com/watch?v=rCYEPg-hFi0