Last active
March 4, 2020 15:46
-
-
Save sibamoussa/656621ffaa1dafdead4bc3950daeef7e to your computer and use it in GitHub Desktop.
GUI for simple calculations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Creator: Siba Moussa | |
#Date: March 4, 2020 | |
#Purpose: Build a GUI for a simple calculator | |
from tkinter import * | |
import tkinter | |
import tkinter.messagebox | |
def proces(): | |
number1 = Entry.get(E1) | |
number2 = Entry.get(E2) | |
operator = Entry.get(E3) | |
number1=int(number1) | |
number2=int(number2) | |
if operator=="+": | |
answer=number1+number2 | |
if operator == "-": | |
answer = number1 - number2 | |
if operator=="*": | |
answer=number1*number2 | |
if operator == "/": | |
answer = number1/number2 | |
Entry.insert(E4,0,answer) | |
print(answer) | |
top=tkinter.Tk() | |
L1=Label(top,text="Siba's calculator").grid(row=0,column=1) | |
L2=Label(top,text="Number1",).grid(row=1,column=0) | |
L3=Label(top,text="Number2",).grid(row=2,column=0) | |
L4=Label(top,text="Operator",).grid(row=3,column=0) | |
L4=Label(top,text="Answer",).grid(row=4,column=0) | |
E1=Entry(top,bd=5) | |
E1.grid(row=1,column=1) | |
E2=Entry(top,bd=5) | |
E2.grid(row=2,column=1) | |
E3=Entry(top, bd=5) | |
E3.grid(row=3,column=1) | |
E4=Entry(top, bd=5) | |
E4.grid(row=4,column=1) | |
B=Button(top,text="Submit",command= proces).grid(row=5,column=1,) | |
top.mainloop() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment