为什么即使我销毁了所有小部件也无法清除框架

时间:2019-07-13 14:58:15

标签: python-3.x tkinter tkinter-canvas

我创建了一个页面来显示历史记录,并创建了两个框架来显示2种不同的搜索和下载历史记录,但是当我将所有历史记录都保留在一页上时,要么将其清除,要么将其清除,或者它本身并没有被破坏

class History:

    def __init__(self,histf):
        self.hframe = histf

        self.chosen = None

        self.ldown = False
        self.lhist = False

        self.create_nbar()

        self.table = None

        self.shframe = Frame(self.hframe,bg='#ffffff',bd=2)
        self.shframe.place(rely = 0.25 ,relx = 0,relwidth = 1 , relheight = 
       0.73)

        self.dhframe = Frame(self.hframe,bg='#ffffff',bd=2)
        self.dhframe.place(rely = 0.25 ,relx = 0,relwidth = 1 , relheight = 
        0.73)

        self.load_sh()

    def next_step(self,parent):
            self.canvas = Canvas(parent,bg = 'blue',bd = 0,highlightthickness 
             = 0)
            self.canvas.place(rely = 0 ,relx = 0.10 ,relwidth = 0.78 , 
            relheight = 1)

            self.vbar = Scrollbar(parent, orient = 'vertical',bg='green')
            self.vbar.pack(side='right',fill='y')
            self.vbar.config(command = self.canvas.yview)

            self.canvas.configure(yscrollcommand=self.vbar.set)

            self.rframe = Frame(self.canvas,bg='red' )
            self.rframe.place(relx=0.0,rely=0,relwidth=1,relheight = 1)

            self.canvas_frame=self.canvas.create_window((0,0), 
            window=self.rframe, anchor="nw",tags="self.rframe")
            self.rframe.bind("<Configure>", self.onFrameConfigure)

            self.canvas.bind('<Configure>', self.update)

            self.bind_mouse_scroll(self.canvas, self.yscroll)
            self.bind_mouse_scroll(self.vbar, self.yscroll)

        def update(self, event):
            height = event.height
            print(height)
           self.vbar.config(command = self.canvas.yview)

        def onFrameConfigure(self, event=None):
            '''Reset the scroll region to encompass the inner frame'''
            print('updating canvas thro7ugh rframe')
            print(self.canvas.bbox('all'))
            self.rframe.update()
            s =self.rframe.winfo_height()
            print(s)
            self.canvas.configure(height = s)
            self.canvas.update()
            self.canvas.configure(scrollregion=self.canvas.bbox("all"))

我用以下代码清除了它:

       def clear_rframe(self):
            print('destruction begin')
            for i in self.rframe.winfo_children():
                  print(f'destroyed : {i}')
                  i.destroy()
                  self.rframe.update_idletasks()
            if self.table == 'search':
                 self.hframe.update_idletasks()
            else:
                 self.dhframe.update_idletasks()

0 个答案:

没有答案