Python 2.7 单击即可打开新窗口,但不显示任何内容[Tkinter]

Python 2.7 单击即可打开新窗口,但不显示任何内容[Tkinter],python-2.7,tkinter,Python 2.7,Tkinter,我使用root作为主要窗口,当人们在其中提出问题时,来自维基百科或WolframAlpha的答案将显示在一个新窗口中。但是,这里发生的情况是新窗口正确打开,但没有显示任何内容 from Tkinter import * import wolframalpha import wikipedia root=Tk() root1=Tk() def getinput(): global entry answer = StringVar() ques=entry.get()

我使用root作为主要窗口,当人们在其中提出问题时,来自维基百科或WolframAlpha的答案将显示在一个新窗口中。但是,这里发生的情况是新窗口正确打开,但没有显示任何内容

from Tkinter import *
import wolframalpha
import wikipedia

root=Tk()
root1=Tk()

def getinput():
    global entry
    answer = StringVar()
    ques=entry.get()
    try:
        #wolframalpha
        app_id = myappid #value of myappid is there in the original code
        client = wolframalpha.Client(app_id)
        res = client.query(ques)
        answer.set(next(res.results).text)
        label=Label(root1, textvariable=answer)

    except:
        #wikipedia
        answer.set(wikipedia.summary(ques).encode('utf-8'))
        label=Label(root1, textvariable=answer)
    label.pack(side=BOTTOM)

root.geometry("350x80+300+300")
label=Label(root, text="Hi! I am Python Digital Assistant. How can I help you today?")
entry=Entry(root)
submit=Button(root, text="Submit", bg="light green", command=getinput)

exit1=Button(root, text="Exit", bg="red", fg="white", command=root.destroy)

label.pack()
entry.pack(fill=X)
entry.focus_set()
submit.pack(side=LEFT)
exit1.pack(side=LEFT)
root.mainloop()
您不必调用TK两次,您必须使用toplevel来实现这一点,当您提供问题并单击submit方法时,答案将在toplevel窗口中弹出

from Tkinter import *
import wolframalpha
import wikipedia

root=Tk()


def getinput():

    top = Toplevel()
    top.geometry("500x500")
    global entry
    answer = StringVar()
    ques=entry.get()
    try:
        #wolframalpha
        app_id = myappid #value of myappid is there in the original code
        client = wolframalpha.Client(app_id)
        res = client.query(ques)
        answer.set(next(res.results).text)
        label=Label(top, textvariable=answer)

    except:
        #wikipedia
        answer.set(wikipedia.summary(ques).encode('utf-8'))
        label=Label(top, textvariable=answer)
    label.pack(side=TOP)

root.geometry("350x80+300+300")
label=Label(root, text="Hi! I am Python Digital Assistant. How can I help you today?")
entry=Entry(root)
submit=Button(root, text="Submit", bg="light green", command=getinput)

exit1=Button(root, text="Exit", bg="red", fg="white", command=root.destroy)

label.pack()
entry.pack(fill=X)
entry.focus_set()
submit.pack(side=LEFT)
exit1.pack(side=LEFT)
root.mainloop()