-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathGorselBasitHesapMakinesi_Tkinter.py
474 lines (393 loc) · 16 KB
/
GorselBasitHesapMakinesi_Tkinter.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
from tkinter import *
from tkinter.messagebox import *
import os
islemDeger=""
sonuc=0
girisAdres=""
gecmisVerileri=[]
#rakamlar
def sayilariEkle(param="0"):
global islemDeger
gecici = listEkran.get(ACTIVE)
if islemDeger == "":
listEkran.delete(0,END)
gecici = gecici + param
listEkran.insert(END,gecici)
elif "=" in gecici:
islemDeger=""
listEkran.delete(0,END)
listEkran.insert(END,param)
else:
listEkran.delete(0,END)
gecici = gecici + param
listEkran.insert(END,gecici)
def sayıYaz1():
sayilariEkle("1")
def sayıYaz2():
sayilariEkle("2")
def sayıYaz3():
sayilariEkle("3")
def sayıYaz4():
sayilariEkle("4")
def sayıYaz5():
sayilariEkle("5")
def sayıYaz6():
sayilariEkle("6")
def sayıYaz7():
sayilariEkle("7")
def sayıYaz8():
sayilariEkle("8")
def sayıYaz9():
sayilariEkle("9")
def sayıYaz0():
sayilariEkle("0")
#işaretler
def islemIsaretDegistir():
gecici = listEkran.get(ACTIVE)
if len(gecici)==0:
pass
elif islemDeger=="":
sayi1 = (-1.0) * float(gecici)
listEkran.delete(0,END)
listEkran.insert(END,str(sayi1))
listeGecmis.insert(END,str(sayi1))
gecmisVerileri.append(str(sayi1)+"\n")
def islemTopla():
global islemDeger
gecici = listEkran.get(ACTIVE)
if len(gecici)==0:
pass
elif islemDeger=="":
islemDeger="+"
listEkran.delete(0,END)
gecici = gecici+ islemDeger
listEkran.insert(END,gecici)
elif len(gecici.split(islemDeger)) == 2:
sayi1=gecici.split(islemDeger)[0]
sayi2=gecici.split(islemDeger)[1]
islemDeger="+"
gecici = sayi1 + islemDeger + sayi2
listEkran.delete(0,END)
listEkran.insert(END,gecici)
def islemCikar():
global islemDeger
gecici = listEkran.get(ACTIVE)
if len(gecici)==0:
pass
elif islemDeger=="":
islemDeger="-"
listEkran.delete(0,END)
gecici = gecici+ islemDeger
listEkran.insert(END,gecici)
elif len(gecici.split(islemDeger)) == 2:
sayi1=gecici.split(islemDeger)[0]
sayi2=gecici.split(islemDeger)[1]
islemDeger="-"
gecici = sayi1 + islemDeger + sayi2
listEkran.delete(0,END)
listEkran.insert(END,gecici)
def islemCarp():
global islemDeger
gecici = listEkran.get(ACTIVE)
if len(gecici)==0:
pass
elif islemDeger=="":
islemDeger="*"
listEkran.delete(0,END)
gecici = gecici+ islemDeger
listEkran.insert(END,gecici)
elif len(gecici.split(islemDeger)) == 2:
sayi1=gecici.split(islemDeger)[0]
sayi2=gecici.split(islemDeger)[1]
islemDeger="*"
gecici = sayi1 + islemDeger + sayi2
listEkran.delete(0,END)
listEkran.insert(END,gecici)
def islemOndalıklıBol():
global islemDeger
gecici = listEkran.get(ACTIVE)
if len(gecici)==0:
pass
elif islemDeger=="":
islemDeger="/"
listEkran.delete(0,END)
gecici = gecici+ islemDeger
listEkran.insert(END,gecici)
elif len(gecici.split(islemDeger)) == 2:
sayi1=gecici.split(islemDeger)[0]
sayi2=gecici.split(islemDeger)[1]
islemDeger="/"
gecici = sayi1 + islemDeger + sayi2
listEkran.delete(0,END)
listEkran.insert(END,gecici)
def islemTamSayiBol():
global islemDeger
gecici = listEkran.get(ACTIVE)
if len(gecici)==0:
pass
elif islemDeger=="":
islemDeger="//"
listEkran.delete(0,END)
gecici = gecici+ islemDeger
listEkran.insert(END,gecici)
elif len(gecici.split(islemDeger)) == 2:
sayi1=gecici.split(islemDeger)[0]
sayi2=gecici.split(islemDeger)[1]
islemDeger="//"
gecici = sayi1 + islemDeger + sayi2
listEkran.delete(0,END)
listEkran.insert(END,gecici)
def islemMod():
global islemDeger
gecici = listEkran.get(ACTIVE)
if len(gecici)==0:
pass
elif islemDeger=="":
islemDeger="%"
listEkran.delete(0,END)
gecici = gecici+ islemDeger
listEkran.insert(END,gecici)
elif len(gecici.split(islemDeger)) == 2:
sayi1=gecici.split(islemDeger)[0]
sayi2=gecici.split(islemDeger)[1]
islemDeger="%"
gecici = sayi1 + islemDeger + sayi2
listEkran.delete(0,END)
listEkran.insert(END,gecici)
def islemUsAl():
global islemDeger
gecici = listEkran.get(ACTIVE)
if len(gecici)==0:
pass
elif islemDeger=="":
islemDeger="^"
listEkran.delete(0,END)
gecici = gecici+ islemDeger
listEkran.insert(END,gecici)
elif len(gecici.split(islemDeger)) == 2:
sayi1=gecici.split(islemDeger)[0]
sayi2=gecici.split(islemDeger)[1]
islemDeger="^"
gecici = sayi1 + islemDeger + sayi2
listEkran.delete(0,END)
listEkran.insert(END,gecici)
def islemEsit():
global islemDeger, sonuc
gecici = listEkran.get(ACTIVE)
if islemDeger != "" and gecici.split(islemDeger)[1] != "":
if "=" in gecici.split(islemDeger)[1]:
indeks = gecici.find("=")
gecici = gecici[0:indeks]
if islemDeger == "+":
sonuc=float(gecici.split(islemDeger)[0]) + float(gecici.split(islemDeger)[1])
elif islemDeger == "-":
if gecici == "-":
sonuc = ((-1)*float(gecici[1:].split(islemDeger)[0])) - float(gecici.split(islemDeger)[1])
else:
sonuc=float(gecici.split(islemDeger)[0]) - float(gecici.split(islemDeger)[1])
elif islemDeger == "*":
sonuc=float(gecici.split(islemDeger)[0]) * float(gecici.split(islemDeger)[1])
elif islemDeger == "/":
if float(gecici.split(islemDeger)[1]) == 0.0:
sonuc = 0.0
else:
sonuc=float(gecici.split(islemDeger)[0]) / float(gecici.split(islemDeger)[1])
elif islemDeger == "//":
if float(gecici.split(islemDeger)[1]) == 0.0:
sonuc = 0.0
else:
sonuc=float(gecici.split(islemDeger)[0]) // float(gecici.split(islemDeger)[1])
elif islemDeger == "%":
if float(gecici.split(islemDeger)[1]) == 0.0:
sonuc=0.0
else:
sonuc=float(gecici.split(islemDeger)[0]) % float(gecici.split(islemDeger)[1])
elif islemDeger == "^":
sonuc=float(gecici.split(islemDeger)[0]) ** float(gecici.split(islemDeger)[1])
listEkran.delete(0,END)
listEkran.insert(END,(gecici+"="+str(sonuc)))
listeGecmis.insert(END,(gecici+"="+str(sonuc)))
gecmisVerileri.append(gecici+"="+str(sonuc)+"\n")
def islemSil():
global islemDeger
gecici = listEkran.get(ACTIVE)
if gecici and gecici[-1] in ["+", "-", "*", "/", "//", "%", "^"]:
if islemDeger == "//":
islemDeger="/"
else:
islemDeger=""
gecici = gecici[:len(gecici)-1]
listEkran.delete(0,END)
listEkran.insert(END,gecici)
def dosyaKaydet():
import datetime
global girisAdres
kayitYeri = girisAdres.get()
# try:
if kayitYeri=="":
showwarning("Uyarı","Lütfen Kayıt yeri ve dosya adını giriniz.")
elif os.path.exists((kayitYeri +".txt")):
showerror("Hata","Bu adreste aynı ada sahip başka bir dosya var. Bu yüzden başka bir dosya adı giriniz.")
else:
#dosya açılıyor.
dosya = open((kayitYeri +".txt"),"w")
#Tarih bilgisi ekleniyor.
gecici=datetime.datetime.now()
tarih = "{}.{}.{} tarihinde {}:{} saatinde dosyaya eklenenler =>\n\n".format(gecici.day,gecici.month,gecici.year,gecici.hour,gecici.minute)
dosya.write(tarih)
#işlemler ekleniyor.
dosya.writelines(gecmisVerileri)
#dosya kapanıyor.
dosya.close()
showinfo("Bilgilendirme","Dosya oluşturularak geçmiş bilgileri kaydedildi.")
# except:
# showerror("Hata","Anlaşılamayan bir hata oluştu")
def dosyaAc():
global girisAdres
kayitYeri=girisAdres.get()
try:
if kayitYeri=="":
showwarning("Uyarı","Lütfen Kayıt yeri ve dosya adını giriniz.")
elif os.path.exists((kayitYeri +".txt")):
os.system("notepad " + (kayitYeri+".txt") )
else:
showerror("Hata","Bu adreste dosya bulunamadı.")
except:
showerror("Hata","Anlaşılamayan bir hata oluştu")
def islemCiktiAl():# ikinci bir pencere oluşturuluyor.
try:
global girisAdres
pencere = Toplevel()
pencere.geometry("420x140+500+100")
pencere.resizable(width=FALSE, height=FALSE)
etiketAdres=Label(pencere, text="""Aşağıdaki alana geçmiş işlemlerin kaydedilmesi istenen yeri giriniz.
Örneğin; C:\Klasör\cıktı.
Burada C:\Klasör\ dosyanın kaydedileceği konum cıktı ise dosyanın adıdır.""")
girisAdres=Entry(pencere,width=68)
butDosyaKaydet = Button(pencere, text = "Kaydet", command=dosyaKaydet)
butDosyaAc = Button(pencere, text = "Dosyayı Aç", command=dosyaAc)
etiketAdres.place(relx=0.0,rely=0.01)
butDosyaKaydet.place(relx=0.1,rely=0.78)
butDosyaAc.place(relx=0.7,rely=0.78)
girisAdres.place(relx=0.01,rely=0.6)
pencere.mainloop()
except:
showerror("Hata","Anlaşılamayan bir hata oluştu")
def islemGecmisTablosuSil():
listeGecmis.delete(0,END)
def islemGecmisiSil():
global gecmisVerileri
gecmisVerileri= []
def islemGecmisTablIslemAktar():
global islemDeger
gecici_islem=listeGecmis.get(ACTIVE)
if "=" not in gecici_islem:
islemDeger=""
listEkran.delete(0,END)
listEkran.insert(END,gecici_islem)
else:
for i in gecici_islem[1:]:
if i in ["+", "-", "*", "/", "//", "%", "^"]:
islemDeger=i
listEkran.delete(0,END)
listEkran.insert(END,gecici_islem.split("=")[0])
break
def islemTamSil():
global islemDeger
listEkran.delete(0,END)
islemDeger=""
def aktar(gecici_islemEkran,gecici_islemGecmis):
if "=" not in gecici_islemGecmis:
listEkran.delete(0,END)
listEkran.insert(END, gecici_islemEkran + gecici_islemGecmis)
else:
listEkran.delete(0,END)
listEkran.insert(END, gecici_islemEkran + gecici_islemGecmis.split("=")[1])
def islemGecmisTablSonucAktar():
global islemDeger
gecici_islemGecmis = listeGecmis.get(ACTIVE)
gecici_islemEkran = listEkran.get(ACTIVE)
if gecici_islemEkran == "":
aktar(gecici_islemEkran,gecici_islemGecmis)
elif islemDeger == "":
gecici_islemEkran=""
aktar(gecici_islemEkran,gecici_islemGecmis)
elif "=" not in gecici_islemEkran:
if gecici_islemEkran[0] != "-":
gecici_islemEkran = gecici_islemEkran.split(islemDeger)[0] + islemDeger
aktar(gecici_islemEkran,gecici_islemGecmis)
else:
gecici_islemEkran = "-" + gecici_islemEkran[1:].split(islemDeger)[0] + islemDeger
aktar(gecici_islemEkran,gecici_islemGecmis)
else:
pass
##############################################################################################################
#Tasarım Kısmı
##############################################################################################################
anaPencere = Tk()
anaPencere.title("Görsel Basit Hesap Makinesi")
anaPencere.geometry("400x600+100+100")
anaPencere.resizable(width=FALSE,height=FALSE)
listEkran = Listbox(anaPencere, width=35,height=2,font="Times 16 bold")
listeGecmis = Listbox(anaPencere,width=35, height=4, bg = "yellow", font="Times 16 bold")
etiketGecmis = Label(anaPencere, text="Geçmiş Tablosu", font="Times 20")
#Sayılar
but1=Button(anaPencere,text="1",width=2,height=2, bg="lightblue", font="Times 20", command=sayıYaz1)
but2=Button(anaPencere,text="2",width=2,height=2, bg="lightblue", font="Times 20", command=sayıYaz2)
but3=Button(anaPencere,text="3",width=2,height=2, bg="lightblue", font="Times 20", command=sayıYaz3)
but4=Button(anaPencere,text="4",width=2,height=2, bg="lightblue", font="Times 20", command=sayıYaz4)
but5=Button(anaPencere,text="5",width=2,height=2, bg="lightblue", font="Times 20", command=sayıYaz5)
but6=Button(anaPencere,text="6",width=2,height=2, bg="lightblue", font="Times 20", command=sayıYaz6)
but7=Button(anaPencere,text="7",width=2,height=2, bg="lightblue", font="Times 20", command=sayıYaz7)
but8=Button(anaPencere,text="8",width=2,height=2, bg="lightblue", font="Times 20", command=sayıYaz8)
but9=Button(anaPencere,text="9",width=2,height=2, bg="lightblue", font="Times 20", command=sayıYaz9)
but0=Button(anaPencere,text="0",width=2,height=2, bg="lightblue", font="Times 20", command=sayıYaz0)
#İslemler
butTopla=Button(anaPencere,text="+",width=2,height=2, bg="lightgreen", font="Times 20", command=islemTopla)
butCikar=Button(anaPencere,text="-",width=2,height=2, bg="lightgreen", font="Times 20", command=islemCikar)
butGecmisTablosuSil=Button(anaPencere, text="Geçmiş Tablosunu Temizle",width=18,height=1, bg="PeachPuff2", fg="gray1", font="Times 12", command=islemGecmisTablosuSil)
butGecmisiSil=Button(anaPencere, text="Geçmiş Bilgilerini Temizle",width=18,height=1, bg="PeachPuff3", fg="black", font="Times 12", command=islemGecmisiSil)
butCarp=Button(anaPencere,text="*",width=2,height=2, bg="lightgreen", font="Times 20", command=islemCarp)
butOndalıklıBol=Button(anaPencere,text="/",width=2,height=2, bg="lightgreen", font="Times 20", command=islemOndalıklıBol)
butTamSayiBol=Button(anaPencere,text="//",width=2,height=2, bg="lightgreen", font="Times 20", command=islemTamSayiBol)
butGecmisTablIslemAktar=Button(anaPencere,text="Geçmiş Tablosundan\nİşlem Aktar",width=16,height=3, bg="PeachPuff2", fg="gray1", font="Times 14", command=islemGecmisTablIslemAktar)
butGecmisTablSonucAktar=Button(anaPencere,text="Geçmiş Tablosundan\nSonuç Aktar",width=16,height=3, bg="PeachPuff2", fg="gray1", font="Times 14", command=islemGecmisTablSonucAktar)
butMod=Button(anaPencere,text="%",width=2,height=2, bg="lightgreen", font="Times 20", command=islemMod)
butIsaretDegistir=Button(anaPencere,text="+/-",width=2,height=2, bg="lightgreen", font="Times 20", command=islemIsaretDegistir)
butUsAl=Button(anaPencere,text="^",width=2,height=2, bg="lightgreen", font="Times 20", command=islemUsAl)
butSil=Button(anaPencere,text="<-",width=2, height=1, bg="black", fg="white", font="Times 15", command=islemSil)
butTamSil=Button(anaPencere,text="SİL",width=2, height=1, bg="white", fg="black", font="Times 15", command=islemTamSil)
butEsit=Button(anaPencere,text="=",width=2,height=2, bg="darkorange", font="Times 20", command=islemEsit)
butGecmisCikti=Button(anaPencere,text="Geçmiş Bilgilerin\nÇıktısını Al",width=13,height=3, bg="PeachPuff2", fg="gray1", font="Times 16", command=islemCiktiAl)
#Ekrana Koyma
but1.place(relx=0.01, rely=0.11)
but2.place(relx=0.12, rely=0.11)
but3.place(relx=0.23, rely=0.11)
but4.place(relx=0.01, rely=0.26)
but5.place(relx=0.12, rely=0.26)
but6.place(relx=0.23, rely=0.26)
but7.place(relx=0.01, rely=0.41)
but8.place(relx=0.12, rely=0.41)
but9.place(relx=0.23, rely=0.41)
but0.place(relx=0.01, rely=0.56)
butTopla.place(relx=0.34, rely=0.11)
butCikar.place(relx=0.45, rely=0.11)
butGecmisiSil.place(relx=0.56, rely=0.11)
butGecmisTablosuSil.place(relx=0.56, rely=0.18)
butCarp.place(relx=0.34, rely=0.26)
butOndalıklıBol.place(relx=0.45, rely=0.26)
butGecmisTablIslemAktar.place(relx=0.56, rely=0.26)
butTamSayiBol.place(relx=0.34, rely=0.41)
butGecmisTablSonucAktar.place(relx=0.56, rely=0.41)
butMod.place(relx=0.45, rely=0.41)
butIsaretDegistir.place(relx=0.12, rely=0.56)
butUsAl.place(relx=0.23, rely=0.56)
butSil.place(relx=0.35, rely=0.56)
butEsit.place(relx=0.45, rely=0.56)
butGecmisCikti.place(relx=0.57, rely=0.56)
butTamSil.place(relx=0.35, rely=0.63)
listEkran.place(relx=0.01,rely=0.01)
listeGecmis.place(relx=0.01,rely=0.81)
etiketGecmis.place(relx=0.01, rely=0.74)
###################################################################################
anaPencere.mainloop()