I've looked at many questions and answers already:
- [1] Refresh a tkinter frame on button press
- [2] Is there a way to refresh a frame?
- [3] Does Tkinter have a refresh method?
- [4] How to refresh the window in Tkinter?
None have the necessary info or are able to answer my question.
Here is a class in my app. This window is called when the user presses the "Mexican" button as a food choice on the previous page. On this page the user is presented with 3 options,
- YES - user likes the restaurant choice and the app quits
- TRY AGAIN - the user still wants Mexican food but not the choice given
- I Don't Want Mexican Anymore - self-explanatory, and goes back to choice of type of restaurant
My question refers to the TRY AGAIN option. I've tried Tk.update, creating a refresh function, lamba function calls, like command=lambda: controller.show_frame(MexicanRest)
but nothing refreshes the current page and allows for the mex_choice = random.choice(mexican_rest)
command to be called again and pick a new restaurant from the mexican_rest
list defined.
You'll see where I've marked the `#WHAT GOES HERE TO REFRESH?" Please advise...
class MexicanRest(tk.Frame):
def __init__(self, parent, controller):
tk.Frame.__init__(self, parent)
label = tk.Label(self, text="Mexican Restaurant",
font=('century gothic', 24))
label.pack(pady=10, padx=10)
mex_choice = random.choice(mexican_rest)
label = tk.Label(self,
text="How does %s sound? " %mex_choice,
bg='yellow',
font=('times', 24),
fg='red')
label.pack()
button1 = tk.Button(self,
text='YES',
width=20,
command=quit)
button1.pack(fill=tk.BOTH)
button2 = tk.Button(self,
text='TRY AGAIN',
width=20,
command=self.refresh) #WHAT GOES HERE TO REFRESH???
button2.pack(fill=tk.BOTH)
button3 = tk.Button(self,
text='I Don\'t Want Mexican Anymore',
#width=20,
command=lambda: controller.show_frame(StartPage))
button3.pack(fill=tk.BOTH)
def refresh(self):
MexicanRest.update(self)