Kaynağa Gözat

更新 'taschenrechner.py'

hzhu 7 yıl önce
ebeveyn
işleme
8511700642
1 değiştirilmiş dosya ile 49 ekleme ve 43 silme
  1. 49 43
      taschenrechner.py

+ 49 - 43
taschenrechner.py

@@ -1,5 +1,52 @@
1 1
 from Tkinter import *
2
+from tkMessageBox import showinfo
3
+#----------------------------------
2 4
 
5
+def response(event):
6
+    I = event.widget['text']
7
+    
8
+    texts = UPN.text.get(1.0,END+'-1c')
9
+    #print texts
10
+
11
+    if I == 'DEL':
12
+        UPN.text.delete(INSERT + '-1c',INSERT)
13
+    elif I == 'Clear':
14
+        UPN.text.delete(1.0,END)
15
+    elif I == 'Enter':
16
+        UPN.text.insert(INSERT,'\n')
17
+    elif I == '=':
18
+		try:
19
+        	s = toList(texts)
20
+        	#print s
21
+        	UPN.text.insert(END,'\n=\n')
22
+        	UPN.text.insert(END,f(s))
23
+        	UPN.text.see('end')
24
+        except:
25
+          	showinfo('Achtung:', 'Falsche Eingabe,bitte ueberpruefen Sie die Eingabe!')
26
+    else:
27
+        UPN.text.insert(INSERT,I)
28
+def UPN():    
29
+    root.title('umgekehrte polnische Notation')
30
+    root.geometry('310x440+200+100')
31
+
32
+    UI = LabelFrame(root)
33
+    UI.place(x = 1,y = 1,width = 308,height = 124)
34
+
35
+    UPN.text = Text(UI)
36
+    UPN.text.place(x=1,y=1,width=300,height=116)
37
+
38
+    Li=[['7','8','9','+','DEL'],
39
+        ['4','5','6','-','Enter'],
40
+        ['1','2','3','*','='],
41
+        ['0','00','.','/','Clear']]
42
+ 
43
+    for i in range(len(Li[0])):
44
+        for j in range(len(Li)):
45
+            bt = Button(root)
46
+            bt.place(x=i*60+10,y=120+(j+1)*60,width=50,height=50)
47
+            bt['text'] = Li[j][i]
48
+            bt.bind('<Button-1>',response,add=(root,))
49
+#----------------------------------
3 50
 def toList(text):
4 51
 	a = text.splitlines()
5 52
     L = []
@@ -60,54 +107,13 @@ def Grundrechenarten(c,a,d):
60 107
         result = int(result)
61 108
 
62 109
     return result
63
-
64
-#-----------------------------
65
-
66
-def response(event):
67
-    I = event.widget['text']
68
-    
69
-    texts = UPN.text.get(1.0,END+'-1c')
70
-    #print texts
71
-
72
-    if I == 'DEL':
73
-        UPN.text.delete(INSERT + '-1c',INSERT)
74
-    elif I == 'Clear':
75
-        UPN.text.delete(1.0,END)
76
-    elif I == 'Enter':
77
-        UPN.text.insert(INSERT,'\n')
78
-    elif I == '=':
79
-        s = toList(texts)
80
-        #print s
81
-        UPN.text.insert(END,'\n=\n')
82
-        UPN.text.insert(END,f(s))
83
-        UPN.text.see('end')
84
-def UPN():    
85
-    root.title('umgekehrte polnische Notation')
86
-    root.geometry('400x500+200+100')
87
-
88
-    UI = LabelFrame(root)
89
-    UI.place(x = 1,y = 1,width = 398,height = 124)
90
-
91
-    UPN.text = Text(UI)
92
-    UPN.text.place(x=1,y=1,width=390,height=116)
93
-
94
-    Li=[['7','8','9','+','DEL'],
95
-        ['4','5','6','-','Enter'],
96
-        ['1','2','3','*','='],
97
-        ['0','00','.','/','Clear']]
98
- 
99
-    for i in range(len(Li[0])):
100
-        for j in range(len(Li)):
101
-            bt = Button(root)
102
-            bt.place(x=(i+1)*60,y=120+(j+1)*60,width=50,height=50)
103
-            bt['text'] = Li[j][i]
104
-            bt.bind('<Button-1>',response,add=(root,))
105
-
110
+#----------------------------------
106 111
 def main():
107 112
     UPN()
108 113
     root.mainloop()
109 114
 
110 115
 if __name__ == '__main__':
116
+    print 'Dieser Taschenrechner ist mit UPN-Eingabe moeglich.'
111 117
     root = Tk()
112 118
     main()
113 119