Tkinter: How to get frame in canvas window to expand to the size of the canvas?

前端 未结 2 898
一向
一向 2020-11-27 20:30

So I\'ve been using the canvas widget in tkinter to create a frame full of labels which has a scrollbar. All is working good except that the frame only expands to the size o

2条回答
  •  醉梦人生
    2020-11-27 20:57

    Just for future reference in case anyone else needs to know:

            frame = Frame(self.bottom_frame)
            frame.pack(side = LEFT, fill = BOTH, expand = True, padx = 10, pady = 10)
    
            self.canvas = Canvas(frame, bg = 'pink')
            self.canvas.pack(side = RIGHT, fill = BOTH, expand = True)
    
            self.mailbox_frame = Frame(self.canvas, bg = 'purple')
    
            self.canvas_frame = self.canvas.create_window((0,0),
                window=self.mailbox_frame, anchor = NW)
            #self.mailbox_frame.pack(side = LEFT, fill = BOTH, expand = True)
    
            mail_scroll = Scrollbar(self.canvas, orient = "vertical", 
                command = self.canvas.yview)
            mail_scroll.pack(side = RIGHT, fill = Y)
    
            self.canvas.config(yscrollcommand = mail_scroll.set)
    
            self.mailbox_frame.bind("", self.OnFrameConfigure)
            self.canvas.bind('', self.FrameWidth)
    
        def FrameWidth(self, event):
            canvas_width = event.width
            self.canvas.itemconfig(self.canvas_frame, width = canvas_width)
    
        def OnFrameConfigure(self, event):
            self.canvas.configure(scrollregion=self.canvas.bbox("all"))
    

提交回复
热议问题