Reputation: 3
My problem is that the first time I run the program it works properly, but when I modify my query and hit the "Go!" button again, nothing happens. I wish it did the same so that when I entered a new query it reloaded the text box with the information corresponding to the last query.
from Tkinter import *
root = Tk()
#Here's an entry box
search_label = Label(root, text="Enter search here:")
search_entry = Entry(root)
search_label.pack()
search_entry.pack()
#This happens when you hit "go!"
def go():
#It opens a text box in which the answer required is written.
query=search_entry.get()
bibliography = Text(root)
bibliography.insert(INSERT, answer_box(query))
bibliography.pack()
#This is the "go!" button
go_button = Button(root, text="Go!", width=10, command=go)
go_button.pack()
root.mainloop()
Some ideas?
Upvotes: 0
Views: 3262
Reputation: 369354
Your code creates text widget every time the button is clicked. Instead of it, create the text widget only once. Then, clear it and insert the answer text.
from Tkinter import *
root = Tk()
search_label = Label(root, text="Enter search here:")
search_entry = Entry(root)
search_label.pack()
search_entry.pack()
def answer_box(query):
return query
def go():
query=search_entry.get()
bibliography.delete('1.0', END)
bibliography.insert(INSERT, answer_box(query))
go_button = Button(root, text="Go!", width=10, command=go)
go_button.pack()
bibliography = Text(root)
bibliography.pack()
root.mainloop()
Upvotes: 1