-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCalculator_list_tkinter.py
More file actions
45 lines (38 loc) · 1.15 KB
/
Calculator_list_tkinter.py
File metadata and controls
45 lines (38 loc) · 1.15 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
from tkinter import *
def clickedChoice():
z = str(listbox.get(listbox.curselection()))
x = int(txtNum1.get())
y = int(txtNum2.get())
if z == 'Add':
z = x + y
if z == 'Sub':
z = x - y
if z == 'Mul':
z = x * y
if z == 'Div':
z = x / y
entryText.set(str(z))
window = Tk()
window.title('List Calculator')
window.geometry("400x250")
var = IntVar()
entryText = StringVar(window)
lblNum1= Label(window,text = "No.1")
lblNum1.grid(row = 0, column = 0)
txtNum1 = Entry(window)
txtNum1.grid(row = 0, column = 1)
lblNum2= Label(window,text = "No.2")
lblNum2.grid(row = 0, column = 2)
txtNum2 = Entry(window)
txtNum2.grid(row = 0, column = 3)
lblChoice = Label(window,text = "Choice").grid(row = 1, column = 0)
listbox = Listbox(window)
listbox.insert(1, "Add")
listbox.insert(2, "Sub")
listbox.insert(3, "Mul")
listbox.insert(4, "Div")
listbox.grid(row = 1, column = 2)
btnSubmit = Button(window, text = "Submit",command=clickedChoice).grid(row = 2, column = 0)
lblAns = Label(window,text = "Ans").grid(row = 3, column = 0)
txtAns = Entry(window,textvariable = entryText).grid(row = 3, column = 1)
window.mainloop()