python - Tkinter: How to get frame in canvas window to expand to the size of the canvas? -
so i've been using canvas widget in tkinter create frame full of labels has scrollbar. working except frame expands size of labels placed in - want frame expand size of parent canvas.
this can done if use pack(expand = true) (which have commented out in code below) frame in canvas then scrollbar doesn't work.
here's appropriate bit of code:
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.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("<configure>", self.onframeconfigure) def onframeconfigure(self, event): self.canvas.configure(scrollregion=self.canvas.bbox("all"))
i've provided image colored frames can see i'm getting at. pink area canvas needs filling mailbox_frame (you can see scrollbar on right):
thanks
set binding on canvas <configure>
event, fires whenever canvas changes size. event object can canvas width , height, , use resize frame.
Comments
Post a Comment