Вам не нужно звонить 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()
![result](https://i.stack.imgur.com/hwMk6.png)