0

I have a problem with a Tkinter scrollbar. I am doing a large message app (something like messenger), but while I try to create a scrolling frame to display all messages my scrollbar isn't showing, it's empty. It's strange that when I've moved the frame with canvas and scrollbar it has worked. I have no idea what's the problem. I hope you will help me.

Here's the code (it's just a piece of it):

class MainScreen:

    def __init__(self, master):
        self.frame2 = LabelFrame(master, bd=0)
        self.frame2.pack(expand=True, fill=BOTH)
        self.msgframe = LabelFrame(self.frame2, bg="#f3f2f1", bd=0)
        self.msgframe.pack(side=RIGHT, expand=True, fill=BOTH
        self.mdframe = LabelFrame(self.msgframe, bg="#f3f2f1")
        self.msgcanvas = Canvas(self.mdframe)
        self.msgscrollbar = Scrollbar(self.mdframe, orient=VERTICAL, 
        command=self.msgcanvas.yview)
        self.second_frame1 = LabelFrame(self.msgcanvas, bg='black')
        self.msgcanvas.config(yscrollcommand=self.msgscrollbar.set,
        bg="green")
        self.msgcanvas.configure(
        scrollregion=self.msgcanvas.bbox("all"))

        self.msgcanvas.create_window((0, 0), 
        window=self.second_frame1, anchor="nw")
        self.mdframe.pack(fill=BOTH, expand=1)
        self.msgcanvas.pack(side=LEFT, fill=BOTH, expand=1)
        self.msgscrollbar.pack(side=RIGHT, fill=Y)

It looks like that: enter image description here

  • 2
    You need to call `.config(scrollregion=...)` after you add all of your widgets inside the frame. Or you can just use the class I wrote [here](https://stackoverflow.com/a/66215091/11106801) – TheLizzard May 31 '21 at 16:44
  • No problem. Do you want me to write a proper answer with an explanation? – TheLizzard Jun 02 '21 at 17:17

0 Answers0