I am trying to learn python and am trying out new projects, in this case a mini calculator. I have been wanting to create a "self-updating" label that prints the inputs that you put into the calculator, for example: 5+5. I am trying to do this with the same variable "Computation" that I have holding the string that is later computed with eval() function. I saw a couple of examples using ".config" and "after" but I can't seem to be able to get it to work. I would appreciate it if someone would be able to help me, thanks!
import tkinter
from tkinter import Button, Tk, ttk, messagebox
root = Tk()
root.geometry("300x150+600+250")
root.configure(background="black")
Computation = ""
VarDisplay = Computation
def Display():
global Computation
VarDisplay.config(Computation=Computation)
root.after(1000, Display)
def Clear():
global Computation
Computation = ""
def Answer ():
global Computation
Computation = eval(Computation)
tkinter.messagebox.showinfo("Answer",Computation)
Computation = ""
def Trolling ():
tkinter.messagebox.showinfo("Greetings", "Hello :)")
def OneFunc ():
global Computation
Computation += "1"
def TwoFunc ():
global Computation
Computation += "2"
def ThreeFunc ():
global Computation
Computation += "3"
def FourFunc ():
global Computation
Computation += "4"
def FiveFunc ():
global Computation
Computation += "5"
def SixFunc ():
global Computation
Computation += "6"
def SevenFunc ():
global Computation
Computation += "7"
def EightFunc ():
global Computation
Computation += "8"
def NineFunc ():
global Computation
Computation += "9"
def ZeroFunc ():
global Computation
Computation += "0"
def AdditionFunc ():
global Computation
Computation += "+"
def MultiplicationFunc ():
global Computation
Computation += "*"
def SubtractionFunc ():
global Computation
Computation += "-"
def DivisionFunc ():
global Computation
Computation += "/"
def PlusMinusFunc ():
global Computation
Computation += "(-)"
def PercentageFunc ():
global Computation
Computation += "/100 *"
def DecimalFunc ():
global Computation
Computation += "."
test = tkinter.Label(root, text="Calc", width = 8).grid(column=0, row=0)
VarDisplay = tkinter.Label(root, text=VarDisplay, width = 20,bg='black',fg='White').grid(column=1,row=0,columnspan=3)
ACButton = ttk.Button(root, text = "AC", width = 5, command = Clear).grid(column=0, row=1)
PlusMinusButton = ttk.Button(root, text = "+ -", width = 5, command = PlusMinusFunc).grid(column=1, row=1)
PercentageButton = ttk.Button(root, text = "%", width = 5, command = PercentageFunc).grid(column=2, row=1)
DivisionButton = ttk.Button(root, text = "/", width = 5, command = DivisionFunc).grid(column=3, row=1)
SevenButton = ttk.Button(root, text = "7", width = 5, command = SevenFunc).grid(column=0, row=2)
EightButton = ttk.Button(root, text = "8", width = 5, command = EightFunc).grid(column=1, row=2)
NineButton = ttk.Button(root, text = "9", width = 5, command = NineFunc).grid(column=2, row=2)
MultiplicationButton = ttk.Button(root, text = "*", width = 5, command = MultiplicationFunc).grid(column=3, row=2)
FourButton = ttk.Button(root, text = "4", width = 5, command = FourFunc).grid(column=0, row=3)
FiveButton = ttk.Button(root, text = "5", width = 5, command = FiveFunc).grid(column=1, row=3)
SixButton = ttk.Button(root, text = "6", width = 5, command = SixFunc).grid(column=2, row=3)
MinusButton = ttk.Button(root, text = "-", width = 5, command = SubtractionFunc).grid(column=3, row=3)
OneButton = ttk.Button(root, text = "1", width = 5, command = OneFunc).grid(column=0, row=4)
TwoButton = ttk.Button(root, text = "2", width = 5, command = TwoFunc).grid(column=1, row=4)
ThreeButton = ttk.Button(root, text = "3", width = 5, command = ThreeFunc).grid(column=2, row=4)
AdditionButton = ttk.Button(root, text = "+", width = 5, command = AdditionFunc).grid(column=3, row=4)
ZeroButton = ttk.Button(root, text = "0", width = 5, command = ZeroFunc).grid(column=0, row=5)
DecimalButton = ttk.Button(root, text = ".", width = 5, command = DecimalFunc).grid(column=1, row=5)
EqualButton = ttk.Button(root, text = "=", width = 5, command = Answer).grid(column=2, row=5)
RandomButton = ttk.Button(root, text = ":)", width = 5, command = Trolling).grid(column=3, row=5)
Display()
root.mainloop()