Tutorials
Tutorial Showcase - Make a PDF Utility in GUI Pie
NOTE - the below tutorials were created in an earlier version of GUI Pie and do not reflect the latest methods. Modifications will need to be made to the main Python files for them to work in GUI Pie 3.0.
These main modifications are to remove the initModules() line, and replace
while True:
gui.run()
with:
gui.run().
Additional modifications may need to be made.
Tutorial 1 - Introduction to Entries, Labels and Buttons
Tutorial 2 - Multi-screened applications
IMPORTANT! Ensure all 3 files are in the same folder! For GUI Pie 3.0, do not include a .run() line for the secondary screen. Ensure the secondary screen is a 'child window' under the window hierarchy property.
Tutorial 3 - Create a calculator
Create a new file named 'calculator.py', and copy and paste in the code from below
Calculator.py
from calculatorGUI import *
from tkinter import messagebox
import math
keys = ['C', '^', '÷', 'x', '7', '8', '9', '-', '4', '5', '6', '+', '1', '2', '3', 'e', '0', '.', 'π', '=']
numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', "."]
operators = ['^', '÷', 'x', '-', '+', 'e', 'π']
names = {"equals":"=" ,"divide":"÷", "minus":"-", "exponent":"^", "plus":"+", "dot":".", "pi":"π"}
def operatorsRemaining(expression):
global operators
result = False
for i in expression:
if i in operators:
result = True
else:
continue
return result
def calculate(expression):
global operators
expression = expression.split()
try:
while operatorsRemaining(expression):
if 'π' in expression:
while 'π' in expression:
if not expression[expression.index('π')-1] in operators:
try:
answer = str(float(expression[expression.index('π')-1]) * math.pi)
expression[expression.index('π')-1] = answer
del expression[expression.index('π')]
except:
expression[expression.index('π')] = str(math.pi)
else:
expression[expression.index('π')] = str(math.pi)
if "e" in expression:
while 'e' in expression:
if not expression[expression.index('e')-1] in operators:
try:
answer = str(float(expression[expression.index('e')-1]) * math.e)
expression[expression.index('e')-1] = answer
del expression[expression.index('e')]
except:
expression[expression.index('e')] = str(math.e)
else:
expression[expression.index('e')] = str(math.e)
for i in expression:
if "^" == i:
answer = str(float(expression[expression.index('^')-1]) ** float(expression[expression.index('^') + 1])) #Unfortunately this repeated section of code cannot be put into a function, as an operation needs to be written in the code, and cannot be based on a variable
expression[expression.index('^')-1] = answer
del expression[expression.index('^')+1]
del expression[expression.index('^')]
for i in expression:
if "x" == i:
answer = str(float(expression[expression.index('x')-1]) * float(expression[expression.index('x') + 1]))
expression[expression.index('x')-1] = answer
del expression[expression.index('x')+1]
del expression[expression.index('x')]
if "÷" == i:
answer = str(float(expression[expression.index('÷')-1]) / float(expression[expression.index('÷') + 1]))
expression[expression.index('÷')-1] = answer
del expression[expression.index('÷')+1]
del expression[expression.index('÷')]
for i in expression:
if "+" == i:
answer = str(float(expression[expression.index('+')-1]) + float(expression[expression.index('+') + 1]))
expression[expression.index('+')-1] = answer
del expression[expression.index('+')+1]
del expression[expression.index('+')]
if "-" == i:
answer = str(float(expression[expression.index('-')-1]) - (float(expression[expression.index('-') + 1])))
expression[expression.index('-')-1] = answer
del expression[expression.index('-')+1]
del expression[expression.index('-')]
except:
messagebox.showerror("Error", "Please input a valid mathematical expression")
return("")
return("".join(expression))
def button(btn):
btn = btn.split("_")[1]
if btn in names:
btn = names.get(btn)
if btn in numbers:
text = calculatorGUI.result.get() + btn
calculatorGUI.result.delete(0, END)
calculatorGUI.result.insert(0, text)
elif btn == "=":
text = calculate(calculatorGUI.result.get())
calculatorGUI.result.delete(0, END)
calculatorGUI.result.insert(0, text)
elif btn == "C":
calculatorGUI.result.delete(0, END)
elif btn == "-":
try:
if calculatorGUI.result.get()[-1] == " ":
text = calculatorGUI.result.get() + btn
calculatorGUI.result.delete(0, END)
calculatorGUI.result.insert(0, text)
else:
text = calculatorGUI.result.get() + " " + btn + " "
calculatorGUI.result.delete(0, END)
calculatorGUI.result.insert(0, text)
except:
text = calculatorGUI.result.get() + btn
calculatorGUI.result.delete(0, END)
calculatorGUI.result.insert(0, text)
else:
text = calculatorGUI.result.get() + " " + btn + " "
calculatorGUI.result.delete(0, END)
calculatorGUI.result.insert(0, text)
calculatorGUI.initModules()
while True:
calculatorGUI.run()