Tkinter ile hesap makinesi

tkinterle basit bir hesap makinesi yaptım paylaşmak istedim:)

import tkinter as tk
import keyboard
from pynput import keyboard
from pynput.keyboard import Listener
pencere = tk.Tk()
pencere['bg']="black"
pencere.geometry("350x200") #350x450
pencere.title("Hesap Makinesi")
islem = tk.Label(text="", bg="black", fg="yellow")
islem.place(x=13, y=10)
butonislem = []

def islemeşittir():
    global butonislem
    karakterdizisi = ""
    for x in butonislem:

        karakterdizisi = karakterdizisi + x
    islemeval = eval(karakterdizisi)
    islem['text']= str(islemeval)
    butonislem.clear()

def islem0():
    global butonislem
    islem['text'] = islem['text'] + buton0['text']
    butonislem.append(buton0['text'])
def islem1():
    global butonislem

    islem['text'] = islem['text'] + buton1['text']
    butonislem.append(buton1['text'])

def islem2():
    global butonislem
    islem['text'] = islem['text'] + buton2['text']
    butonislem.append(buton2['text'])
def islem3():
    global butonislem
    islem['text'] = islem['text'] + buton3['text']
    butonislem.append(buton3['text'])

butonlar123 = []
buton1 = tk.Button(text="1", width=3, command=islem1)
buton2 = tk.Button(text="2", width=3, command=islem2)
buton3 = tk.Button(text="3", width=3, command=islem3)
butonlar123.append(buton1)
butonlar123.append(buton2)
butonlar123.append(buton3)
xdeger123 = 13
ydeger123 = 45

for x in butonlar123:

    x.place(x=xdeger123, y=ydeger123)
    xdeger123 += 31

butonlar456 = []
def islem4():
    global butonislem
    islem['text'] = islem['text'] + buton4['text']
    butonislem.append(buton4['text'])
def islem5():
    global butonislem
    islem['text'] = islem['text'] + buton5['text']
    butonislem.append(buton5['text'])
def islem6():
    global butonislem
    islem['text'] = islem['text'] + buton6['text']
    butonislem.append(buton6['text'])
buton4 = tk.Button(text="4", width=3, command=islem4)
buton5 = tk.Button(text="5", width=3,  command=islem5)
buton6 = tk.Button(text="6", width=3,  command=islem6)
butonlar456.append(buton4)
butonlar456.append(buton5)
butonlar456.append(buton6)
xdeger456 = 13 #15
ydeger456 = 80
for x in butonlar456:

    x.place(x=xdeger456, y=ydeger456)
    xdeger456 += 31

def islem7():
    global butonislem
    islem['text'] = islem['text'] + buton7['text']
    butonislem.append(buton7['text'])
def islem8():
    global butonislem
    islem['text'] = islem['text'] + buton8['text']
    butonislem.append(buton8['text'])
def islem9():
    global butonislem
    #islem['text']=""
    islem['text'] = islem['text'] + buton9['text']
    butonislem.append(buton9['text'])
butonlar789 = []
buton7 = tk.Button(text="7", width=3, command=islem7)
buton8 = tk.Button(text="8", width=3, command=islem8)
buton9 = tk.Button(text="9", width=3, command=islem9)
buton7.place(x=15, y=115)
butonlar789.append(buton7)
butonlar789.append(buton8)
butonlar789.append(buton9)
xdeger789 = 13 #15
ydeger789 = 115
for x in butonlar789:

    x.place(x=xdeger789, y=ydeger789)
    xdeger789 += 31
def islemartı():
    global butonislem
    islem['text']= ""
    butonislem.append(artı['text'])
def islemeksi():
    global butonislem
    islem['text'] = ""
    butonislem.append(eksi['text'])
def islemçarpma():
    global  butonislem
    islem['text'] = ""
    butonislem.append("*")
def islembölme():
    global butonislem
    islem['text'] = ""
    butonislem.append("/")
def islembuton():
    islem['text'] = islem['text'].rstrip(islem['text'][-1])
buton = tk.Button(text="C", width=3, height=8, command=islembuton)
buton.place(x=155, y=ydeger123)
artı = tk.Button(text="+",width=3, command=islemartı)
artı.place(x=115, y=ydeger123)
eksi = tk.Button(text="-", width=3, command=islemeksi)
eksi.place(x=115, y=ydeger456)
çarpma = tk.Button(text="X", width=3, command=islemçarpma)
çarpma.place(x=115, y=ydeger789)
bölme  = tk.Button(text="÷", width=3, command=islembölme)
bölme.place(x=115, y=ydeger789+(ydeger789-ydeger456))
buton0 = tk.Button(text="0", width=3, command=islem0)
buton0.place(x=13, y=ydeger789+((ydeger789-ydeger456)))
#b = tk.Button(text="qwjwn", command=lambda : print(*butonislem))
#b.pack()
eşittir  = tk.Button(text="=", width=7, command=islemeşittir)
eşittir.place(x=44,y=ydeger789+((ydeger789-ydeger456)) )

pencere.mainloop()
2 Beğeni

Bence hiç tkinterle uğraşma çünkü ileride bunu exeye çevirip kullanamayacaksın.

Sebep?
20 karakter…

En azından pyinstaller ile kullanamayacaksın. Çünkü ben bunu çok denedim ama olmadı.

Sen yapamamış olabilirsin tkinter pyinstaller hiç sorun yaşamadım anti virüs saçmalıklarını saymazsak tabi.

https://imgur.com/rOEmBLf.png hata alıyorum

Yazıyo orda çözümü…

20 karaker

tkinter i bende daha önce exe ye çevirmiştim ancak tkinter sadece pc de kullanılıyordu yanlış hatırlamıyorsam yani apk felan yapamazsınız ben de o sebeple kivy e başlamıştım her yerde kullanabiliyorsunuz ancak gene de istediğinizi kullanmak size kalmıştır :slight_smile:

1 Beğeni

sizce ne kullanmalıyım??

PyQt5 veya PyQt, pyside, kivy, wxpython vb.

Ama tkinker çok ilkel bir gui kütüphanesidir.

# SUBJECT - BUILD A SIMPLE CALCULATOR

from tkinter import *

root = Tk()
root.title("SIMPLE CALCULATOR")

e = Entry(root, width=35, borderwidth=5)
e.grid(row=0, column=0, columnspan=3, padx=10, pady=10)


def button_click(number):
    # e.delete(0, END)
    current = e.get()
    e.delete(0, END)
    e.insert(0, str(current) + str(number))
    return


def button_clear():
    e.delete(0, END)


def button_plus():
    first_number = e.get()
    global f_num
    global math
    math = "addition"
    f_num = int(first_number)
    e.delete(0, END)


def equal():
    second_number = e.get()
    e.delete(0, END)
    if math == "addition":
        e.insert(0, f_num + int(second_number))
    if math == "subtraction":
        e.insert(0, f_num - int(second_number))
    if math == "multiplication":
        e.insert(0, f_num * int(second_number))
    if math == "division":
        e.insert(0, f_num / int(second_number))


def button_subtract():
    first_number = e.get()
    global f_num
    global math
    math = "subtraction"
    f_num = int(first_number)
    e.delete(0, END)


def button_multiply():
    first_number = e.get()
    global f_num
    global math
    math = "multiplication"
    f_num = int(first_number)
    e.delete(0, END)


def button_divide():
    first_number = e.get()
    global f_num
    global math
    math = "division"
    f_num = int(first_number)
    e.delete(0, END)


# Define Buttons and put the buttons on screen

button_1 = Button(root, text="1", padx=40, pady=20, command=lambda: button_click(1)).grid(row=3, column=0)
button_2 = Button(root, text="2", padx=40, pady=20, command=lambda: button_click(2)).grid(row=3, column=1)
button_3 = Button(root, text="3", padx=40, pady=20, command=lambda: button_click(3)).grid(row=3, column=2)

button_4 = Button(root, text="4", padx=40, pady=20, command=lambda: button_click(4)).grid(row=2, column=0)
button_5 = Button(root, text="5", padx=40, pady=20, command=lambda: button_click(5)).grid(row=2, column=1)
button_6 = Button(root, text="6", padx=40, pady=20, command=lambda: button_click(6)).grid(row=2, column=2)

button_7 = Button(root, text="7", padx=40, pady=20, command=lambda: button_click(7)).grid(row=1, column=0)
button_8 = Button(root, text="8", padx=40, pady=20, command=lambda: button_click(8)).grid(row=1, column=1)
button_9 = Button(root, text="9", padx=40, pady=20, command=lambda: button_click(9)).grid(row=1, column=2)

button_0 = Button(root, text="0", padx=40, pady=20, command=lambda: button_click(0)).grid(row=4, column=0)
button_add = Button(root, text="+", padx=39, pady=20, command=button_plus).grid(row=5, column=0)
button_equal = Button(root, text="=", padx=91, pady=20, command=equal).grid(row=5, column=1,
                                                                                             columnspan=2)
button_clear = Button(root, text="Clear", padx=79, pady=20, command=button_clear).grid(row=4, column=1,
                                                                                                 columnspan=2)

button_subtract = Button(root, text="-", padx=41, pady=20, command=button_subtract).grid(row=6, column=0)
button_multiply = Button(root, text="*", padx=40, pady=20, command=button_multiply).grid(row=6, column=1)
button_divide = Button(root, text="/", padx=41, pady=20, command=button_divide).grid(row=6, column=2)

root.mainloop()

# columspan = occupied line

Daha önce tkinter ile yazmıştım. Feyz alabilirsin

1 Beğeni

kod dizisini uygulamaya nasıl çeviriyoruz yeniyimde

ellerinize sağlık peki birşey sorucam geçenlerde aklıma bi fikir geldi tkinterdan belli komutu verdiğimde, windows un hesap makinesini açma gibi bi komut yazılabilirmi hesap makinesi yapmak kolay ama yapması çok zor veyda imkansıza yakın kodlarda direk hazır olanları açmam mümkünmü

yazılır tabi neden olmasın. Örnek verelim;

from os import system

system("calc.exe")

Bu kodu çalıştırınca system içerisinde yazılanlar direkt cmd üzerinden çalıştırılır. Windows için konuşuyoruz.

teşekkür ederim birkaç saat sonra deneme fırsatım olacak ozaman denerim tekrardan sağolun

ohaa denedim ve sadece yolladığın kodları yazdım kendi kodlarıma ilave etmedim ama direk önce cmd 2sn içinde kapanıp hesap makinesi açıldı tekrardan teşşekkğr ederim ve calc.exe neye göre yazdık calc ı yani başka şeyleri nasıl açıcaz bide ben pycharm da kütüphane ismi nedir

yaptım çalıştı fakat pycharmda kütüphanesni bulamıyorum

windows komut satırından yapılacak şeyleri, windows a ait uygulamarın komut satırından çalıştırılacak karşılık isimlerini araştırıp öğrenmek lazım. python os modülünü öğrenmek lazım.

birşey sorucam aynı şekilde web sitesine nsdıl yönlendirebilirim