a_4_button_gui
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionNext revisionBoth sides next revision | ||
a_4_button_gui [2016/08/10 20:39] – walkeradmin | a_4_button_gui [2017/02/04 22:00] – [The Code] walkeradmin | ||
---|---|---|---|
Line 2: | Line 2: | ||
\\ | \\ | ||
\\ | \\ | ||
- | ** NOTE ** You need Python 3 for this project, the syntax wont work in Python 2 (but can be changed If you know the differences) | + | ** NOTE ** You need **Python 3** for this project, the syntax wont work in Python 2 (but can be changed If you know the differences) |
\\ | \\ | ||
\\ | \\ | ||
Line 9: | Line 9: | ||
\\ | \\ | ||
This is an example of using something in Python called Tkinter, which has many funcitons for creating GUI's (forms, labels, buttons etc) and the following code will create a 4 button app where a function is executed depending on what button is pressed. | This is an example of using something in Python called Tkinter, which has many funcitons for creating GUI's (forms, labels, buttons etc) and the following code will create a 4 button app where a function is executed depending on what button is pressed. | ||
+ | \\ | ||
+ | \\ | ||
+ | This GUI can be used on an LCD Touchscreen, | ||
\\ | \\ | ||
\\ | \\ | ||
Line 14: | Line 17: | ||
\\ | \\ | ||
\\ | \\ | ||
- | You can download | + | This program does the following: |
+ | |||
+ | * Creates a window (root) | ||
+ | * Creates 2 frames to go in that window (topFrame | ||
+ | * Creates 4 Icons | ||
+ | * Loads an image on to each Icon | ||
+ | * Associates each button with a function | ||
+ | * Sets button 1 and 2 in the top frame | ||
+ | * Sets button 2 in the bottom frame | ||
+ | \\ | ||
+ | ===== See the Program in Action ===== | ||
+ | \\ | ||
+ | {{:4buttonguivideo.mp4?640x360|}} | ||
+ | {{:4buttonactual.mp4? | ||
\\ | \\ | ||
+ | ===== The Code ===== | ||
\\ | \\ | ||
+ | You can download the code and icon files {{ : | ||
+ | ---- | ||
+ | |||
+ | <sxh [py][; options for SyntaxHighlighter]> | ||
# Python 3.4.2\\ | # Python 3.4.2\\ | ||
#\\ | #\\ | ||
Line 36: | Line 57: | ||
from tkinter import * #import libraries\\ | from tkinter import * #import libraries\\ | ||
\\ | \\ | ||
- | def btn1click(): | + | def btn1click(): |
- | \\ # thats why its at the top of the programe\\ | + | |
print(" | print(" | ||
\\ | \\ | ||
Line 53: | Line 73: | ||
\\ | \\ | ||
topFrame = Frame(root) #This project will have 2 frames, an upper and a lower. 2 icons in top, 2 in bottom\\ | topFrame = Frame(root) #This project will have 2 frames, an upper and a lower. 2 icons in top, 2 in bottom\\ | ||
- | #without the frames, its impossible to organise the 4 icons in a 2x2 configuration\\ | + | #without the frames, its impossible to organise the 4 icons in a 2x2 configuration\\ |
- | | + | #topFrame is the frame at the top, Frame=(root) means the frame is in the root window\\ |
topFrame.pack() | topFrame.pack() | ||
bottomFrame = Frame (root) | bottomFrame = Frame (root) | ||
Line 60: | Line 81: | ||
\\ | \\ | ||
button1 = Button(topFrame, | button1 = Button(topFrame, | ||
- | #call it button 1, make the forground colour (text) red.\\ | + | #call it button 1, make the forground colour (text) red.\\ |
button1.img = PhotoImage(file=" | button1.img = PhotoImage(file=" | ||
button1.config(image=button1.img) | button1.config(image=button1.img) | ||
Line 85: | Line 106: | ||
button4.pack(side=RIGHT)\\ | button4.pack(side=RIGHT)\\ | ||
\\ | \\ | ||
- | root.mainloop()\\ | + | root.mainloop() |
+ | |||
+ | </ | ||
+ | \\ | ||
\\ | \\ | ||
+ | |||
+ | ---- | ||
+ | |||
\\ | \\ |
a_4_button_gui.txt · Last modified: 2023/03/09 22:35 by 127.0.0.1