8000 Simple GUI Calculator · danjethh/programminginpython.com@3c882db · GitHub
[go: up one dir, main page]

Skip to content

Commit 3c882db

Browse files
committed
Simple GUI Calculator
1 parent b413512 commit 3c882db

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

simple_calci.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
__author__ = 'Avinash'
2+
3+
import tkinter as tk
4+
from functools import partial
5+
6+
7+
def call_result(label_result, n1, n2):
8+
num1 = (n1.get())
9+
num2 = (n2.get())
10+
result = int(num1)+int(num2)
11+
label_result.config(text="Result is %d" % result)
12+
return
13+
14+
root = tk.Tk()
15+
root.geometry('400x200+100+200')
16+
root.title('Simple Calculator')
17+
18+
number1 = tk.StringVar()
19+
number2 = tk.StringVar()
20+
21+
labelTitle = tk.Label(root, text="Simple Calculator").grid(row=0, column=2)
22+
labelNum1 = tk.Label(root, text="Enter a number").grid(row=1, column=0)
23+
labelNum2 = tk.Label(root, text="Enter another number").grid(row=2, column=0)
24+
labelResult = tk.Label(root)
25+
labelResult.grid(row=7, column=2)
26+
27+
entryNum1 = tk.Entry(root, textvariable=number1).grid(row=1, column=2)
28+
entryNum2 = tk.Entry(root, textvariable=number2).grid(row=2, column=2)
29+
call_result = partial(call_result, labelResult, number1, number2)
30+
buttonCal = tk.Button(root, text="Calculate", command=call_result).grid(row=3, column=0)
31+
root.mainloop()

0 commit comments

Comments
 (0)
0