0

我从 Codeskulptor 获取我的代码并将其放入 pycharm 中。我想出了如何去做import simplegui,但是当我运行解决方案并在输入必要的内容后单击一个按钮时,我收到一条错误消息

line 16, in click
    a=float(inA.get_text())
AttributeError: 'Input' object has no attribute 'get_text'.

这是完整的代码:

import simpleguitk as simplegui

a=1
b=1
c=1
d=1
deriv=0

def click():
    global a,b,c,d
    a=float(inA.get_text())
    b=float(inB.get_text())
    c=float(inC.get_text())
    d=float(inD.get_text())
    label1.set_text('Current equation: '+str(a)+"x²+"+str(b)+"x+"+str(c))
    deriv= 2.0*a*d + b
    label2.set_text('Slope of graph at x='+str(d)+": "+str(deriv))


def draw_handler(canvas):
    z =[]
    for x in range (-150,150):
        y=a*x**2+b*x+c
        z.append([(x)+150,(150-(y))])
        list(z)
    canvas.draw_polyline(z, 1, 'Red')
    canvas.draw_line((150,0),(150,700),1,"white")
    canvas.draw_line((0,150),(700,150),1,"white")

def donothing():
    q=2

frame = simplegui.create_frame('Testing',300,300)#graphx , graph y)
frame.set_draw_handler(draw_handler)
frame.add_button("Click me",click)

inA= frame.add_input("A value",donothing, 30)
inB= frame.add_input("B value",donothing, 30)
inC= frame.add_input("C value",donothing, 30)
inD= frame.add_input("Find Slope at X=",donothing, 30)
label1 = frame.add_label('Current equation: ')
label2 = frame.add_label('Slope at X=')
frame.start()

有没有一种我不知道的在 pycharm 中获取文本的不同方式?

谢谢

4

0 回答 0