1

やあみんな最初の投稿、そしてそうではないこんにちは。とにかくtkinterで関数電卓を作ろうとしていて、私はそれがあまり得意ではありません(そしてpythonは私の2番目の適切な割り当てです)。とにかく、ほとんどのコードはおそらく間違っているでしょうが、一度に 1 つずつ実行しようとしているだけです。特に、関数 add について心配しています。ボタンを介して呼び出していますが、do関数に+を渡したいです。これにより、計算できる配列が作成されます。エラーが発生し続け、修正方法がわかりません。今は本当に迷惑なので、誰かが助けてくれれば大歓迎です

from tkinter import*
from operator import*

class App:
    def __init__(self,master):#is the master for the button widgets
        frame=Frame(master)
        frame.pack()
        self.addition = Button(frame, text="+", command=self.add)#when clicked sends a call back for a +
        self.addition.pack()
    def add(Y):
        do("+")
    def do(X):#will hopefully colaborate all of the inputs
        cont, i = True, 0
        store=["+","1","+","2","3","4"]
        for i in range(5):
            X=store[0+i]
            print(store[0+i])
            cont = False
        if cont == False:
            print(eval_binary_expr(*(store[:].split())))
    def get_operator_fn(op):#allows the array to be split to find the operators
        return {
            '+' : add,
            '-' : sub,
            '*' : mul,
            '/' : truediv,
            }[op]
    def eval_binary_expr(op1, num1, op2, num2):
        store[1],store[3] = int(num1), int(num2)
        return get_operator_fn(op2)(num1, num2)


root=Tk()
app=App(root)
root.mainloop()#runs programme
4

1 に答える 1