从tkinter 3打印输出有问题

时间:2014-08-27 13:48:06

标签: python-3.x tkinter

我写了这段代码来帮助我完成几何作业。现在真的很简单。现在的代码如下所示:

from tkinter import *
root = Tk()
mainframe = Frame(root)
mainframe.grid()

a=Label(root,text = "X")
a.grid(row=1, column=1)
x=Entry(root)
x.grid(row=1, column=2)
y=Entry(root)
y.grid(row=3, column=2)
b=Label(root,text="Y")
b.grid(row=3, column=1)
x3=Entry(root)
x3.grid(row=1, column=5)
c=Label(root,text = "x3")
c.grid(row=1, column=4)
y3=Entry(root)
y3.grid(row=3,column=5)
d=Label(root,text = "y3")
d.grid(row=3, column=4)
label=Label(root).grid(row=2,column=9,columnspan=3)
k=Label(root,text ="M(Slope)")
k.grid(row=1,column=6)
l=Entry(root).grid(row=2,column=6)





def midpoint():
    e=((float(x.get())+(float(x3.get())))/2.0)
    f=((float(y.get())+(float(y3.get())))/2.0)
    print ("Midpoint = (",e,",",f,")")

def slope():
    h=((float(y3.get())-(float(y.get()))))
    i=((float(x3.get())-(float(x.get()))))
    print ('Slope = ',h,'/',i,'')

g=Button(root, text="Midpoint", command=midpoint).grid(row=7,column=1)
j=Button(root,text="slope", command=slope).grid(row=7,column=2)
mainloop()  

问题是当我点击中点按钮时,我明白了:

Midpoint = (

然后,当我再次点击它时,我得到了这个:

Midpoint = ( 2.0 , 3.0 )
Midpoint = (

我不太清楚为什么会这样。我想要做的第二件事是重命名变量,所以我制作了这样的代码只是为了让它变得更容易:

x1=(float(x.get())
y1=(float(y.get())
x2=(float(x3.get())
y2=(float(y3.get())

然而它给我一个语法错误,我不知道为什么。任何帮助,将不胜感激。感谢

0 个答案:

没有答案