-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI Caculator using Tkinter Module in Python
More file actions
55 lines (48 loc) · 2.6 KB
/
Copy pathGUI Caculator using Tkinter Module in Python
File metadata and controls
55 lines (48 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#GUI Caculator by @Winston
from tkinter import *
master=Tk()
master.configure(background="silver")
master.geometry("265x225")
master.title("GUI Cacu by Winston")
equation=StringVar()
expression=""
def press(num):
global expression
expression = expression+str(num)
equation.set(expression)
def equalpress():
try:
global expression
total = str(eval(expression))
equation.set(total)
expression = ""
except:
equation.set("Error")
expression=""
def clear():
global expression
expression=""
equation.set(expression)
expression_field = Entry(master,textvariable=equation).grid(columnspan=50,ipadx=70)
#Buttons
button1 = Button(master,text="1",width="8",height="2",command=lambda:press(1)).grid(row=1,column=1)
button2 = Button(master,text="2",width="8",height="2",command=lambda:press(2)).grid(row=1,column=2)
button3 = Button(master,text="3",width="8",height="2",command=lambda:press(3)).grid(row=1,column=3)
button4 = Button(master,text="4",width="8",height="2",command=lambda:press(4)).grid(row=2,column=1)
button5 = Button(master,text="5",width="8",height="2",command=lambda:press(5)).grid(row=2,column=2)
button6 = Button(master,text="6",width="8",height="2",command=lambda:press(6)).grid(row=2,column=3)
button7 = Button(master,text="7",width="8",height="2",command=lambda:press(7)).grid(row=3,column=1)
button8 = Button(master,text="8",width="8",height="2",command=lambda:press(8)).grid(row=3,column=2)
button9 = Button(master,text="9",width="8",height="2",command=lambda:press(9)).grid(row=3,column=3)
button0 = Button(master,text="0",width="8",height="2",command=lambda:press(0)).grid(row=4,column=2)
decimal = Button(master,text=".",width="8",height="2",command=lambda:press(".")).grid(row=5,column=1)
button00 = Button(master,text="00",width="8",height="2",command=lambda:press("00")).grid(row=5,column=3)
#Signs
plus = Button(master,text="+",width="8",height="2",command=lambda:press("+")).grid(row=4,column=1)
minus = Button(master,text="-",width="8",height="2",command=lambda:press("-")).grid(row=4,column=3)
multiplier = Button(master,text="x",width="8",height="2",command=lambda:press("*")).grid(row=1,column=4)
divid = Button(master,text="÷",width="8",height="2",command=lambda:press("/")).grid(row=2,column=4)
remainder = Button(master,text="Remainder",width="8",height="2",command=lambda:press("%")).grid(row=3,column=4)
equal = Button(master,text="=",background="blue",width="8",height="2",command=equalpress).grid(row=4,column=4)
Clear = Button(master, text="Clear",background="red",width="8",height="2",command=clear).grid(row=5,column=2)
master.mainloop()