python - Tkinter programming -


i've made basic tk window , kept button delete widgets imprint of widgets left over.

how can remove blank part? problem still persists

from tkinter import *  class window(frame):    def __init__(self, master=none):     frame.__init__(self, master)                      self.master = master     self.init_window()   def init_window(self):        self.master.title("sample")     self.pack(expand=1)     loginb = button(self, text="log in",command=self.login, height=2, width=20)     loginb.grid(row=1)    def quit(self):         exit()   def login(self):         widget in frame.winfo_children(self):               widget.destroy()         self.grid_forget()         self.grid()         e1         self.l = {}         label1 = label(text="enter code:").grid(row=1,column=0)         e1 = entry(textvariable=e1).grid(row=1,column=1)         def  f1():               self.l["code"] = e1.get()               return         b1 = button(text="ok", command=f1).grid(row=1,column=2) root = tk() root.geometry("700x700") app = window(root) root.mainloop() 

you need remove frame well. it's frame leftover.

def login(self):     widget in frame.winfo_children(self):         widget.destroy()     self.pack_forget() 

looking @ menu though, need buttons again instead of re-creating them each time after using widget.destroy(), should use widget.grid_forget() , use widget.grid() when needed again.

edit: added dummy menu button show how add other widgets

class window(frame):   def __init__(self, master=none):     ...     ...     ...     ...     file.add_command(label="dummybutton", command=self.add_widget)    def login(self):         widget in frame.winfo_children(self):               widget.destroy()         self.pack_forget()    def add_widget(self):       #here packing again       #since pack doesn't remember config options,        #you need specify here expand etc.       self.pack(expand=1)        #adding dummy widget show adds without problem       button(self, text="dummy widget").pack() 

Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -