I am making a simple calculator which only adds the user's input. Based on what I have tried I want to put the results in box just like the entry field. What should I add or edit?
I also want to ask on how to bold the error message.. Thank you.
What I have tried:
from tkinter import *
import tkinter.messagebox
window = Tk()
window.geometry("350x200")
window.resizable(0, 0)
window.title("Simple Cal")
l1 = Label(window, text="First Number:", font=("Arial", 11, "bold")).grid(row=0)
e = Entry(window, width=27, bd=3, bg="#eee", justify=CENTER)
e.grid(column=1, row=0)
e.get()
l2 = Label(window, text="Second Number:", font=("Arial", 11, "bold")).grid(row=1)
f = Entry(window, width=27, bd=3, bg="#eee", justify=CENTER)
f.grid(column=1, row=1)
f.get()
def button_add():
try:
num1 = e.get()
num2 = f.get()
sum = float(num1) + float(num2)
num = sum
myLabel = Label(window, font=("Arial", 12), text=num)
myLabel.grid(column=1, row=3)
except ValueError:
tkinter.messagebox.showinfo('ERROR!', 'Value Error. Please fix them.')
myButton = Button(window, width=13, text="Add", bd=4, bg="#eee", highlightbackground="black", highlightthickness=1, justify=RIGHT, command=button_add)
myButton.grid(columnspan=3)
window.mainloop()