-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMyfilewithPython.py
98 lines (98 loc) · 3.12 KB
/
MyfilewithPython.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from tkinter import *
wd = Tk()
wd.title("Casio Calculator")
def bt_click(number):
e.insert(END,number)
def addition():
global num1
num1 = int(e.get())
e.delete(0,END)
global operator
operator = 1
def subtraction():
global num1
num1 = int(e.get())
e.delete(0,END)
global operator
operator = 2
def multiplication():
global num1
num1 = int(e.get())
e.delete(0,END)
global operator
operator = 3
def division():
global num1
num1 = int(e.get())
e.delete(0,END)
global operator
operator = 4
def square_root():
global num1
num1 = int(e.get())
e.delete(0,END)
global operator
operator = 5
def power():
global num1
num1 = int(e.get())
e.delete(0,END)
global operator
operator = 6
def calculation():
global num1
global operator
num2 = int(e.get())
e.delete(0,END)
if operator == 1:
e.insert(0,num1+num2)
if operator == 2:
e.insert(0,num1-num2)
if operator == 3:
e.insert(0,num1*num2)
if operator == 4:
e.insert(0,num1/num2)
if operator == 5:
e.insert(0,num2**(1/num1))
if operator == 6:
e.insert(0,num1**num2)
#Giao diện ứng dụng (User Interface)
e = Entry(width=20,bd=5,font="Courier 18",justify=RIGHT)
bt_7 = Button(text="7",width=10,height=3,command=lambda: bt_click(7))
bt_8 = Button(text="8",width=10,height=3,command=lambda: bt_click(8))
bt_9 = Button(text="9",width=10,height=3,command=lambda: bt_click(9))
bt_div = Button(text="/",width=10,height=3,command=division)
bt_4 = Button(text="4",width=10,height=3,command=lambda: bt_click(4))
bt_5 = Button(text="5",width=10,height=3,command=lambda: bt_click(5))
bt_6 = Button(text="6",width=10,height=3,command=lambda: bt_click(6))
bt_mul = Button(text="*",width=10,height=3,command=multiplication)
bt_1 = Button(text="1",width=10,height=3,command=lambda: bt_click(1))
bt_2 = Button(text="2",width=10,height=3,command=lambda: bt_click(2))
bt_3 = Button(text="3",width=10,height=3,command=lambda: bt_click(3))
bt_sub = Button(text="-",width=10,height=3,command=subtraction)
bt_clear = Button(text="Clear",width=10,height=3,command=lambda:e.delete(0,END))
bt_0 = Button(text="0",width=10,height=3,command=lambda: bt_click(0))
bt_eq = Button(text="=",width=10,height=3,command=calculation)
bt_add = Button(text="+",width=10,height=3,command=addition)
bt_square_root = Button(text="√",width=10,height=3,command=square_root)
bt_power = Button(text="^",width=10,height=3,command=power)
e.grid(row=0,column=0,columnspan=4,pady=10)
bt_7.grid(row=1,column=0)
bt_8.grid(row=1,column=1)
bt_9.grid(row=1,column=2)
bt_div.grid(row=1,column=3)
bt_4.grid(row=2,column=0)
bt_5.grid(row=2,column=1)
bt_6.grid(row=2,column=2)
bt_mul.grid(row=2,column=3)
bt_1.grid(row=3,column=0)
bt_2.grid(row=3,column=1)
bt_3.grid(row=3,column=2)
bt_sub.grid(row=3,column=3)
bt_clear.grid(row=4,column=0)
bt_0.grid(row=4,column=1)
bt_eq.grid(row=4,column=2)
bt_add.grid(row=4,column=3)
bt_square_root.grid(row=5,column=0)
bt_power.grid(row=5,column=1)
wd.mainloop()