1
嘿家伙第一篇文章,什么不那么喜。无论如何,试图用tkinter制作一个科学计算器,即时通讯并不是很好(而Python是我的第二个适当的任务)。无论如何,大部分的代码可能是错误的,但即时通讯只是一步一个脚印,特别是关注函数add。即时通过按钮调用它,但我想通过do函数a +。这反过来创建一个数组我可以从中计算。它不断错误,我不知道如何解决它。它真的讨厌我现在这样,如果有人可以帮帮忙,将不胜感激tkinter按钮按功能调用
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
即时尝试按顺序将“+”添加到数组所以当我有其他按钮时,我可以输入整个方程而不必按每个数字输入。正如我所说,虽然即时通讯仍然刚刚开始,所以它可能会相当inefficent代码(和或不工作),但只是顶部帮助了卡车负载我couldent找出为什么它wouldent工作。 – akronicillness