-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcalculator program using tkinter
More file actions
40 lines (32 loc) · 1002 Bytes
/
Copy pathcalculator program using tkinter
File metadata and controls
40 lines (32 loc) · 1002 Bytes
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
import tkinter as tk
from tkinter import messagebox
root=tk.Tk()
root.title("My first GUI")
root.geometry("400x400")
tk.Label(root,text="Number 1").pack()
e1=tk.Entry(root)
e1.pack()
tk.Label(root,text="Number 2").pack()
e2=tk.Entry(root)
e2.pack()
def operation1():
n1=int(e1.get())
n2=int(e2.get())
messagebox.showinfo("addition:",f"sum= {n1+n2}")
def operation2():
n1=int(e1.get())
n2=int(e2.get())
messagebox.showinfo("substraction:",f"substraction= {n1-n2}")
def operation3():
n1=int(e1.get())
n2=int(e2.get())
messagebox.showinfo("multiplication:",f"multiplication= {n1*n2}")
def operation4():
n1=int(e1.get())
n2=int(e2.get())
messagebox.showinfo("division:",f"division= {n1/n2}")
tk.Button(root,text="addition",command=operation1).pack()
tk.Button(root,text="substraction",command=operation2).pack()
tk.Button(root,text="multiplication",command=operation3).pack()
tk.Button(root,text="division",command=operation4).pack()
root.mainloop()