Refresh a tkinter frame on button press

前端 未结 3 1044
悲哀的现实
悲哀的现实 2021-01-17 03:54

I am utilising code from Switch between two frames in tkinter to make my GUI. I have a frame with refresh and restart buttons.

My original idea was for the restart

3条回答
  •  攒了一身酷
    2021-01-17 04:09

    The first step is to have your button call a proper function rather than using lambda. Unless you understand why and when to use lambda, it usually just makes the code harder to write and understand.

    Once you have it call a function, you can use the function to clear the entries.

    Example:

    class PLG(tk.Frame):
        def __init__(self, parent, controller):
            ...
            tk.Button(self, text="Restart", command=self.restart)
            tk.Button(self, text="Refresh", command=self.refresh)
            ...
    
        def restart(self):
            self.refresh()
            self.controller.show_frame("StartPage")
    
        def refresh(self):
            self.weight_entry.delete(0, "end")
            self.text.delete("1.0", "end")
    

提交回复
热议问题