How to Clear the window in tkinter (Python)? -


i want hide/remove buttons window (temporarily) "hide_widgets" function can put them after not working me, have tried using grid_hide() , destroy() , have tried searching stackoverflow not worked either.

here program far:

from tkinter import *  class application(frame):     #gui application      def __init__(self, master):         #initialize frame         frame.__init__(self,master)         self.grid()         self.create_widgets()      def create_widgets(self):         #create new game etc...          #title         self.title = label(self,text = "gnome")         self.title.grid()          #new game         self.new_game = button(self,text = "new game")         self.new_game ["command"] = self.create_new_game         self.new_game.grid()          #load game         self.load_game = button(self,text = "load game")         self.load_game ["command"] = self.display_saves         self.load_game.grid()          #settings         self.settings = button(self,text = "settings")         self.settings ["command"] = self.display_settings         self.settings.grid()          #story         self.story = button(self,text = "story")         self.story ["command"] = self.display_story         self.story.grid()          #credits         self.credits = button(self,text = "credits")         self.credits ["command"] = self.display_credits         self.credits.grid()      def hide_widgets(self):         #clear window         new_game.grid_forget()      def create_new_game(self):         #create new game file         self.hide_widgets         self.instruction = label(self, text = "name world:")         self.instruction.grid()          self.world_name = entry(self)         self.world_name.grid()      def display_saves(self):         #display saved games , allow run         print("saves")      def display_settings(self):         #display settings , allow alter         print("settings")      def display_story(self):         #display story         print("story")      def display_credits(self):         #display credits         print("credits")  root = tk() root.title("welcome") width, height = root.winfo_screenwidth(), root.winfo_screenheight() root.geometry('%dx%d+0+0' % (width,height)) app = application(root)  root.mainloop() 

thank in advance.

you can hide buttons calling each one's grid_forget() method.

to make easier might want create self.buttons list or dictionary contains them all.

alternatively there's grid_slaves() method might able use on application instance give list of widgest manages (or ones in specified row or column). buttons should in 1 of these lists. i've never used it, don't know how easy identify them in list returned however.


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -