a_4_button_gui
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| a_4_button_gui [2016/08/10 19:41] – walkeradmin | a_4_button_gui [2017/02/04 22:02] (current) – [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 11: | Line 11: | ||
| \\ | \\ | ||
| \\ | \\ | ||
| - | {{: | + | This GUI can be used on an LCD Touchscreen, |
| \\ | \\ | ||
| \\ | \\ | ||
| - | You can download the code and icon files {{ :40x2_lcd.zip |Here:}} | + | {{:4buttonguiscreenshot.jpg?300|}} |
| \\ | \\ | ||
| \\ | \\ | ||
| + | This program does the following: | ||
| - | ---- | + | * Creates a window (root) |
| - | + | * Creates | |
| - | # Python 3.4.2\\ | + | * Creates 4 Icons |
| - | #\\ | + | * Loads an image on to each Icon |
| - | # Test programme for doing a simple 4 button GUI\\ | + | * Associates each button |
| - | #\\ | + | * Sets button 1 and 2 in the top frame |
| - | # Alan Walker\\ | + | * Sets button 2 in the bottom frame |
| - | # Aug 2016\\ | + | |
| - | #\\ | + | |
| - | #\\ | + | |
| - | # This programe creates a root window, then creates two frame in that root window (topFrame and bottomFrame)\\ | + | |
| - | # Then four buttons are created, two in the top frame, two in the bottom. An image is loaded | + | |
| - | # Each button | + | |
| - | # The buttons are positioned left and right so you have a 2x2 layout\\ | + | |
| - | #\\ | + | |
| - | # Thats it, this is just a tester for my LCD screen that I want to use for my Intervalometer.\\ | + | |
| - | #\\ | + | |
| - | #\\ | + | |
| \\ | \\ | ||
| - | from tkinter import * #import libraries\\ | + | ===== See the Program in Action ===== |
| \\ | \\ | ||
| - | def btn1click(): # define a function (you have to define it before you can call it, thats why its at the top of the programe\\ | + | {{:4buttonguivideo.mp4? |
| - | print(" | + | {{: |
| \\ | \\ | ||
| - | def btn2click(): | + | ===== The Code ===== |
| - | print(" | + | |
| \\ | \\ | ||
| - | def btn3click(): | + | You can download |
| - | print(" | + | ---- |
| - | \\ | + | |
| - | def btn4click(): | + | |
| - | print(" | + | |
| - | \\ | + | |
| - | \\ | + | |
| - | root = Tk() #This is the root window, all the frames will be in this window\\ | + | |
| - | \\ | + | |
| - | 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\\ | + | |
| - | #topFrame is the frame at the top, Frame=(root) means the frame is in the root window\\ | + | |
| - | topFrame.pack() | + | <sxh [py][; options for SyntaxHighlighter]> |
| - | bottomFrame = Frame (root) | + | # Python 3.4.2 |
| - | bottomFrame.pack(side=BOTTOM) #place the bottom frame at the bottom (by default, the only other frame will be at the top)\\ | + | # |
| - | \\ | + | # Test programme for doing a simple 4 button GUI |
| - | button1 = Button(topFrame, | + | # |
| - | #call it button 1, make the forground colour (text) red.\\ | + | # Alan Walker |
| - | button1.img = PhotoImage(file=" | + | # Aug 2016 |
| - | button1.config(image=button1.img) | + | # |
| - | button1.config(command=btn1click) | + | # |
| - | \\ | + | # This programe creates a root window, then creates two frame in that root window (topFrame and bottomFrame) |
| - | button2 = Button(topFrame, | + | # Then four buttons are created, two in the top frame, two in the bottom. An image is loaded on to each button |
| - | button2.img = PhotoImage(file=" | + | # Each button is assigned to a function so that something happens when the buttons are clicked. |
| - | button2.config(image=button2.img)\\ | + | # The buttons are positioned left and right so you have a 2x2 layout |
| - | button2.config(command=btn2click)\\ | + | # |
| - | \\ | + | # Thats it, this is just a tester for my LCD screen that I want to use for my Intervalometer. |
| - | button3 = Button(bottomFrame, | + | # |
| - | button3.img = PhotoImage(file=" | + | # |
| - | button3.config(image=button3.img)\\ | + | |
| - | button3.config(command=btn3click)\\ | + | from tkinter import * #import libraries |
| - | \\ | + | |
| - | button4 = Button(bottomFrame, | + | def btn1click(): |
| - | button4.img = PhotoImage(file=" | + | print(" |
| - | button4.config(image=button4.img)\\ | + | |
| - | button4.config(command=btn4click) | + | def btn2click(): |
| - | \\ | + | print(" |
| - | button1.pack(side=LEFT) | + | |
| - | button2.pack(side=RIGHT) | + | def btn3click(): |
| - | button3.pack(side=LEFT)\\ | + | print(" |
| - | button4.pack(side=RIGHT)\\ | + | |
| + | def btn4click(): | ||
| + | print(" | ||
| + | |||
| + | |||
| + | root = Tk() #This is the root window, all the frames will be in this window | ||
| + | |||
| + | 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 | ||
| + | #topFrame is the frame at the top, Frame=(root) means the frame is in the root window | ||
| + | |||
| + | topFrame.pack() | ||
| + | bottomFrame = Frame (root) | ||
| + | bottomFrame.pack(side=BOTTOM) #place the bottom frame at the bottom (by default, the only other frame will be at the top) | ||
| + | |||
| + | button1 = Button(topFrame, | ||
| + | #call it button 1, make the forground colour (text) red. | ||
| + | button1.img = PhotoImage(file=" | ||
| + | button1.config(image=button1.img) | ||
| + | button1.config(command=btn1click) | ||
| + | |||
| + | button2 = Button(topFrame, | ||
| + | button2.img = PhotoImage(file=" | ||
| + | button2.config(image=button2.img) | ||
| + | button2.config(command=btn2click) | ||
| + | |||
| + | button3 = Button(bottomFrame, | ||
| + | button3.img = PhotoImage(file=" | ||
| + | button3.config(image=button3.img) | ||
| + | button3.config(command=btn3click) | ||
| + | |||
| + | button4 = Button(bottomFrame, | ||
| + | button4.img = PhotoImage(file=" | ||
| + | button4.config(image=button4.img) | ||
| + | button4.config(command=btn4click) | ||
| + | |||
| + | button1.pack(side=LEFT) | ||
| + | button2.pack(side=RIGHT) | ||
| + | button3.pack(side=LEFT) | ||
| + | button4.pack(side=RIGHT) | ||
| + | |||
| + | root.mainloop() | ||
| + | |||
| + | # | ||
| + | # | ||
| + | </ | ||
| \\ | \\ | ||
| - | root.mainloop()\\ | ||
| \\ | \\ | ||
a_4_button_gui.1470858109.txt.gz · Last modified: (external edit)
