Skip to content
Menu
Daniel J. Pierce
  • C#
  • Games
  • Graphics
  • Math
  • Python
  • Tynker
  • Unity
Daniel J. Pierce

Simple Tkinter Calculator

Posted on September 5, 2019November 11, 2019

Run this in a machine that supports tkinter.

FYI: My mom helped me with this project

[python]
from tkinter import *
from tkinter import ttk
import re


root = Tk()


equation = ''
labell = ttk.Label(root, text = equation); labell.grid(row = 0,columnspan = 4)
'textbox'
def combine(bar):
    global equation
    if type(bar) != str:
        clear()
    equation += bar
    global labell
    labell.config(text = equation)
def equal():
    global equation
    if re.search('[0-9]\(', equation):
        re.sub('\(', '\*\(', equation)
    equation = str(eval(equation))
    global labell
    labell.config(text = equation)
def backspace():
    global equation
    equation = equation[:-1]
    labell.config(text = equation)
def clear():
    global equation
    #labell.destroy()
    
    equation = ''
    global labell
    labell.config(text= equation)


    
    
from math import *
'''typable textbox
powers
roots
factorials
graphing?
percent
pi
e
sin, cos, tan, cosh, sinh, tanh, log, antifunction
variable setting?
'''
#    if equation = a number, and bar is a function(+/) then continue the equation instead of clearing it after pressing equals
power = ttk.Button(root, text='^', command=lambda: combine('**')).grid(row=5, column=0)
one = ttk.Button(root, text = '1', command =lambda: combine('1')).grid(row = 3, column = 0)
two = ttk.Button(root, text = '2', command=lambda: combine('2')).grid(row = 3, column = 1)
three = ttk.Button(root, text='3', command=lambda: combine('3')).grid(row=3, column=2)
four = ttk.Button(root, text = '4', command =lambda: combine('4')).grid(row = 2, column = 0)
five=ttk.Button(root, text='5', command=lambda: combine('5')).grid(row=2, column=1)
six=ttk.Button(root, text='6', command=lambda: combine('6')).grid(row=2, column=2)
seven=ttk.Button(text = '7', command=lambda: combine('7')).grid(row = 1, column = 0)
eight=ttk.Button(root, text='8', command=lambda: combine('8')).grid(row=1, column=1)
nine=ttk.Button(root, text='9', command=lambda: combine('9')).grid(row=1, column=2)
zero=ttk.Button(root, text='0', command=lambda: combine('0')).grid(row=4,  column=1,columnspan = 2,sticky='we')
decimalPoint=ttk.Button(root, text='.', command=lambda: combine('.')).grid(row=4, column=0)
plus=ttk.Button(root, text='+', command=lambda: combine('+')).grid(row=3, column=3)
minus=ttk.Button(root, text='-', command=lambda: combine('-')).grid(row=3, column=4)
multiply=ttk.Button(root, text='*', command=lambda: combine('*')).grid(row=2, column=3)
divide=ttk.Button(root, text='/', command=lambda: combine('/')).grid(row=2, column=4)
parrenthesesOpen=ttk.Button(root, text='(', command=lambda: combine('(')).grid(row=1, column=3)
parrenthesesClose=ttk.Button(root, text=')', command=lambda: combine(')')).grid(row=1, column=4)
solve=ttk.Button(root, text='=', command=equal).grid(row=4, column=3, columnspan=2, sticky='we')
clearr=ttk.Button(root, text='CLEAR', command=clear).grid(row=5, column=3, columnspan=2, sticky='we')
delete=ttk.Button(root, text='DEL', command=backspace).grid(row=5, column=1, columnspan=2, sticky='we')

Label(root, text=equation).pack


[/python]

Projects

  • Procedure Platforming
  • Particle Simulator
  • AP Computer Science Paint Program
  • Maybe Good Platformer
  • Custom Gravity Test
  • Triangle Types
  • Unity Obstacle Course v1
  • Collapsing rows
  • Java Tic Tac Toe (No AI)
  • Mersenne Prime Tester
  • Rainbow
  • Pong
  • Simple Tkinter Calculator
  • Hexidecimal Converter
  • Snake eats apple
  • Protect the Galactic Empire
  • Hangman
  • Beautiful Colorful Thing
  • Four Dots
  • Frogga
  • Escape asteroids
  • Portals
  • Guess the Number 2.0
  • Illogical
  • Tic Tac Toe
  • Guess the Number
  • Ultimate Calculator 1.0.0a0
  • Prime Number Tester
  • Number Base Converter 2.0a0
  • Number Base Converter 1.1
  • Python Equation Calculator
©2025 Daniel J. Pierce | WordPress Theme by Superb WordPress Themes