Python graphics.py hesap makinesi

RaPGoD31

Picopat
Katılım
20 Kasım 2020
Mesajlar
6
Sadece graphics.py kullanarak bir hesap makinesi tasarladım ama operatörleri göstermemesi gerek, yani +'ya basınca ekranda olan sayılar kalsın sonra bastığım sayıların ekrana yazılması lazım.

Python:
from graphics import *

def Arda():
 arda = GraphWin("Calculator", 600, 600)
 arda.setCoords(0.0,0.0,6.0,6.0)
 result = Entry(Point(3,5.50),20)
 start = Text(Point(3,5.9),"Arda's calculator")
 start.draw(arda)
 num = "0"
 result.setText(num)
 result.draw(arda)
 arrf = []
 arrt = []
 x = 3.
 y = 3.
 i=0.
 j=9.
 k=0.
 z=0.
 while j>=0:
 arrf.append(Point(x,y))
 arrt.append(Point(x+1.5,y+1))
 btn = Rectangle(Point(x,y),Point(x+1.5,y+1))
 btn.draw(arda)
 num = Text(Point(x+0.75,y+0.5),str(j))
 num.draw(arda)
 x -= 1.5.
 j -= 1.
 i += 1.
 k += 1.
 z += 1.
 if i==3:
 x = 3.
 y = 2.
 i = 0.
 if k==6:
 x=3.
 y=1.
 k=0.
 if z==10:
 x=0.
 y=0.
 arrf[z-1] = (Point(x,y))
 arrt[z-1] = (Point(x+3,y+1))
 btn = Rectangle(Point(x, y), Point(x + 3, y + 1))
 btn.draw(arda)
 num.undraw()
 num = Text(Point(x+1.5,y+0.5),str(j+1))
 num.draw(arda)
 z=0.
 ops = ["AC","+/-","%","/","x","-","+","**","="]
 j = 0.
 x = 0.
 y = 4.
 i = 0.
 while j<len(ops):
 arrf.append(Point(x, y))
 arrt.append(Point(x + 1.5, y + 1))
 btn = Rectangle(Point(x, y), Point(x + 1.5, y + 1))
 btn.draw(arda)
 num = Text(Point(x + 0.75, y + 0.5), str(ops[j]))
 num.draw(arda)
 x += 1.5.
 i += 1.
 j += 1.
 if i==4:
 x = 4.5.
 y = 3.
 if i==5:
 x = 4.5.
 y = 2.
 if i==6:
 x = 4.5.
 y = 1.
 if i==7:
 x=3.
 y=0.
 i=0.
 numv = ""
 clk = True.
 while clk:
 ch = arda.getMouse()
 if (ch.x > arrf[0].x and ch.x < arrt[0].x and ch.y > arrf[0].y and ch.y < arrt[0].y):
 numv = numv+"9"
 if (ch.x > arrf[1].x and ch.x < arrt[1].x and ch.y > arrf[1].y and ch.y < arrt[1].y):
 numv = numv+"8"
 if (ch.x > arrf[2].x and ch.x < arrt[2].x and ch.y > arrf[2].y and ch.y < arrt[2].y):
 numv = numv +"7"
 if (ch.x > arrf[3].x and ch.x < arrt[3].x and ch.y > arrf[3].y and ch.y < arrt[3].y):
 numv = numv +"6"
 if (ch.x > arrf[4].x and ch.x < arrt[4].x and ch.y > arrf[4].y and ch.y < arrt[4].y):
 numv = numv +"5"
 if (ch.x > arrf[5].x and ch.x < arrt[5].x and ch.y > arrf[5].y and ch.y < arrt[5].y):
 numv = numv +"4"
 if (ch.x > arrf[6].x and ch.x < arrt[6].x and ch.y > arrf[6].y and ch.y < arrt[6].y):
 numv = numv +"3"
 if (ch.x > arrf[7].x and ch.x < arrt[7].x and ch.y > arrf[7].y and ch.y < arrt[7].y):
 numv = numv +"2"
 if (ch.x > arrf[8].x and ch.x < arrt[8].x and ch.y > arrf[8].y and ch.y < arrt[8].y):
 numv = numv +"1"
 if (ch.x > arrf[9].x and ch.x < arrt[9].x and ch.y > arrf[9].y and ch.y < arrt[9].y):
 numv = numv +"0"
 if (ch.x > arrf[10].x and ch.x < arrt[10].x and ch.y > arrf[10].y and ch.y < arrt[10].y):
 numv = ""
 if (ch.x > arrf[11].x and ch.x < arrt[11].x and ch.y > arrf[11].y and ch.y < arrt[11].y):
 numv = "-" + result.getText()
 if (ch.x > arrf[12].x and ch.x < arrt[12].x and ch.y > arrf[12].y and ch.y < arrt[12].y):
 numv = numv + "%"
 if (ch.x > arrf[13].x and ch.x < arrt[13].x and ch.y > arrf[13].y and ch.y < arrt[13].y):
 numv = numv +"/"
 if (ch.x > arrf[14].x and ch.x < arrt[14].x and ch.y > arrf[14].y and ch.y < arrt[14].y):
 numv = numv +"*"
 if (ch.x > arrf[15].x and ch.x < arrt[15].x and ch.y > arrf[15].y and ch.y < arrt[15].y):
 numv = numv+"-"
 if (ch.x > arrf[16].x and ch.x < arrt[16].x and ch.y > arrf[16].y and ch.y < arrt[16].y):
 numv = numv+"+"
 if (ch.x > arrf[17].x and ch.x < arrt[17].x and ch.y > arrf[17].y and ch.y < arrt[17].y):
 numv = numv+"**"
 if (ch.x > arrf[18].x and ch.x < arrt[18].x and ch.y > arrf[18].y and ch.y < arrt[18].y):
 try :
 result.setText(str(eval(numv)))
 numv = ""
 except SyntaxError:
 numv = numv[1:]
 result.setText(str(eval(numv)))
 numv = ""
 continue.
 if (ch.x > 5.99):
 break.
 result = Entry(Point(3, 5.50), 20)
 result.draw(arda)
 result.setText(numv)

Arda()

Bu kısmı halledince neredeyse bitiyor, yardımcı olan olursa çok sevinirim.
 
Son düzenleyen: Moderatör:
txt olarak attım.


Python:
from graphics import *

def Arda():
    arda = GraphWin("Calculator", 600, 600)
    arda.setCoords(0.0,0.0,6.0,6.0)
    result = Entry(Point(3,5.50),20)
    start = Text(Point(3,5.9),"Calculator")
    start.draw(arda)
    num = "0"
    result.setText(num)
    result.draw(arda)
    arrf = []
    arrt = []
    x = 3
    y = 3
    i=0
    j=9
    k=0
    z=0
    while j>=0:
        arrf.append(Point(x,y))
        arrt.append(Point(x+1.5,y+1))
        btn = Rectangle(Point(x,y),Point(x+1.5,y+1))
        btn.draw(arda)
        num = Text(Point(x+0.75,y+0.5),str(j))
        num.draw(arda)
        x -= 1.5
        j -= 1
        i += 1
        k += 1
        z += 1
        if i==3:
            x = 3
            y = 2
            i = 0
        if k==6:
            x=3
            y=1
            k=0
        if z==10:
            x=0
            y=0
            arrf[z-1] = (Point(x,y))
            arrt[z-1] = (Point(x+3,y+1))
            btn = Rectangle(Point(x, y), Point(x + 3, y + 1))
            btn.draw(arda)
            num.undraw()
            num = Text(Point(x+1.5,y+0.5),str(j+1))
            num.draw(arda)
            z=0
    ops = ["AC","+/-","%","/","x","-","+","**","="]
    j = 0
    x = 0
    y = 4
    i = 0
    while j<len(ops):
        arrf.append(Point(x, y))
        arrt.append(Point(x + 1.5, y + 1))
        btn = Rectangle(Point(x, y), Point(x + 1.5, y + 1))
        btn.draw(arda)
        num = Text(Point(x + 0.75, y + 0.5), str(ops[j]))
        num.draw(arda)
        x += 1.5
        i += 1
        j += 1
        if i==4:
            x = 4.5
            y = 3
        if i==5:
            x = 4.5
            y = 2
        if i==6:
            x = 4.5
            y = 1
        if i==7:
            x=3
            y=0
            i=0
    numv = ""
    clk = True
    while clk:
        ch = arda.getMouse()
        if (ch.x > arrf[0].x and ch.x < arrt[0].x and ch.y > arrf[0].y and ch.y < arrt[0].y):
            numv = numv+"9"
        if (ch.x > arrf[1].x and ch.x < arrt[1].x and ch.y > arrf[1].y and ch.y < arrt[1].y):
            numv = numv+"8"
        if (ch.x > arrf[2].x and ch.x < arrt[2].x and ch.y > arrf[2].y and ch.y < arrt[2].y):
            numv = numv +"7"
        if (ch.x > arrf[3].x and ch.x < arrt[3].x and ch.y > arrf[3].y and ch.y < arrt[3].y):
            numv = numv +"6"
        if (ch.x > arrf[4].x and ch.x < arrt[4].x and ch.y > arrf[4].y and ch.y < arrt[4].y):
            numv = numv +"5"
        if (ch.x > arrf[5].x and ch.x < arrt[5].x and ch.y > arrf[5].y and ch.y < arrt[5].y):
            numv = numv +"4"
        if (ch.x > arrf[6].x and ch.x < arrt[6].x and ch.y > arrf[6].y and ch.y < arrt[6].y):
            numv = numv +"3"
        if (ch.x > arrf[7].x and ch.x < arrt[7].x and ch.y > arrf[7].y and ch.y < arrt[7].y):
            numv = numv +"2"
        if (ch.x > arrf[8].x and ch.x < arrt[8].x and ch.y > arrf[8].y and ch.y < arrt[8].y):
            numv = numv +"1"
        if (ch.x > arrf[9].x and ch.x < arrt[9].x and ch.y > arrf[9].y and ch.y < arrt[9].y):
            numv = numv +"0"
        if (ch.x > arrf[10].x and ch.x < arrt[10].x and ch.y > arrf[10].y and ch.y < arrt[10].y):
            numv = ""
        if (ch.x > arrf[11].x and ch.x < arrt[11].x and ch.y > arrf[11].y and ch.y < arrt[11].y):
            numv = "-" + result.getText()
        if (ch.x > arrf[12].x and ch.x < arrt[12].x and ch.y > arrf[12].y and ch.y < arrt[12].y):
            numv = numv + "%"
        if (ch.x > arrf[13].x and ch.x < arrt[13].x and ch.y > arrf[13].y and ch.y < arrt[13].y):
            numv = numv +"/"
        if (ch.x > arrf[14].x and ch.x < arrt[14].x and ch.y > arrf[14].y and ch.y < arrt[14].y):
            numv = numv +"*"
        if (ch.x > arrf[15].x and ch.x < arrt[15].x and ch.y > arrf[15].y and ch.y < arrt[15].y):
            numv = numv+"-"
        if (ch.x > arrf[16].x and ch.x < arrt[16].x and ch.y > arrf[16].y and ch.y < arrt[16].y):
            numv = numv+"+"
        if (ch.x > arrf[17].x and ch.x < arrt[17].x and ch.y > arrf[17].y and ch.y < arrt[17].y):
            numv = numv+"**"
        if (ch.x > arrf[18].x and ch.x < arrt[18].x and ch.y > arrf[18].y and ch.y < arrt[18].y):
            try :
                result.setText(str(eval(numv)))
                numv = str(eval(numv))
            except SyntaxError:
                numv = numv[1:]
                result.setText(str(eval(numv)))
                numv = str(eval(numv))
            continue
        if (ch.x > 5.99):
            break
        result = Entry(Point(3, 5.50), 20)
        result.draw(arda)
        result.setText(numv)

Arda()
 

Dosya Ekleri

  • graphics.txt
    30,8 KB · Görüntüleme: 45
Uyarı! Bu konu 5 yıl önce açıldı.
Muhtemelen daha fazla tartışma gerekli değildir ki bu durumda yeni bir konu başlatmayı öneririz. Eğer yine de cevabınızın gerekli olduğunu düşünüyorsanız buna rağmen cevap verebilirsiniz.

Technopat Haberler

Yeni konular

Geri
Yukarı