将输出打印到GUI上

时间:2014-08-27 15:51:41

标签: python python-3.x tkinter

我有这个代码,我希望输出打印到GUI而不是python shell。代码如下所示:

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

add=Label(root,text ="M(Slope)")
add.grid(row=1,column=6)
k=Entry(root)
k.grid(row=2,column=6)
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 = "X")
c.grid(row=1, column=4)
y3=Entry(root)
y3.grid(row=3,column=5)
d=Label(root,text = "Y")
d.grid(row=3, column=4)

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

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

def distance():
    x1=(float(x.get()))
    y1=(float(y.get()))
    x2=(float(x3.get()))
    y2=(float(y3.get()))    
    m= (x2 - x1)
    n=(y2 - y1)
    o = (m*m)
    p = (n*n)
    q = (o + p)
    print('Distance = v',q,'')

def pointslope():
    x1=(float(x.get()))
    y1=(float(y.get()))
    k4 = (float(k.get()))
    s = (0.0-y1)
    t = (0.0-x1)
    u = (k4*t)
    if s > 0:
        v = (u-s)
    else:
        v = (abs(s)+u)
    if v > 0:
        print ('y =',k4,'x +',v,'')
    else:
        print ('y=',k4,'x',v,'')


g=Button(root, text="Midpoint", command=midpoint).grid(row=7,column=1)
j=Button(root,text="slope", command=slope).grid(row=7,column=2)
r = Button(root, text = "distance", command = distance).grid(row=7,column = 3)
w =Button(root, text = "pointslope", command = pointslope).grid(row = 7, column = 5)
root.mainloop()

我希望将答案打印到tkinter模块而不是shell上。有谁知道怎么做???

1 个答案:

答案 0 :(得分:0)

是:

>>> root = Tk()                                        # .DEF Tk()
>>> another = Toplevel( root )                         # .SET <another>, sub of <root>
>>> another.title("GUI<-output")                       # .GUI show .title
''
>>> L = Label( another, text="<process>-output text" ) # .SET Label in <another>
>>> L.pack()                                           # .PACK
>>> another.lift()                                     # .GUI ensure visibility
>>> L['text'] = L['text'] + "\n" + getAnotherTEXT()    # .MOD text in <another>