Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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()
Posted
Updated 26-May-21 21:32pm

1 solution

 
Share this answer
 
Comments
lil_mint 27-May-21 8:18am    
Thank you!!!!!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900