简体   繁体   中英

tkinter - Scrollbar will not show

I am having a developing a GUI in Python and there is no scrollbar that shows when I run it. It get an empty bar with arrows, but there is no scrollbar inside and the scrollbar does not work at all.

#Scroll Functions
    def ScrollAll(event):
        self.topcanvas.config(scrollregion = self.topcanvas.bbox("all"))
    def on_mousewheel(event):
        self.topcanvas.yview('scroll',0, 'units')

    #topframe
    topframe = Frame(master, background = '#D9F7FE', width = 2100, height = 1700)
    topframe.place(x = 0, y = 0)

    #Top canvas
    self.topcanvas = Canvas(topframe, scrollregion = (0, 0, 1000, 1000))
    self.topcanvas.pack(side = TOP, fill = BOTH, expand = TRUE)
    self.topcanvas.config(width = 2100, height =1700, background = '#D9F7FE')

    #scroll
    self.vbar = ttk.Scrollbar(master, orient = 'vertical', command = self.topcanvas.yview)
    #self.hbar = ttk.Scrollbar(master, orient = 'horizontal', command = self.topcanvas.xview)
    #self.topcanvas.config(xscrollcommand = self.hbar.set)
    self.topcanvas.config(yscrollcommand = self.vbar.set)

    #self.hbar.pack(side = "bottom", fill = "x")
    self.vbar.pack(side = "right", fill = "y")
    self.topcanvas.pack(side="left")
    self.topcanvas.bind_all("<MouseWheel>", on_mousewheel)

    #frame
    frame = Frame(self.topcanvas)
    frame.config(width = 2100, height = 1700,background = '#D9F7FE') 
    self.topcanvas.create_window((0,0), window = frame, anchor = 'nw')
    frame.bind("<Configure>", ScrollAll)

我的滚动区域必须大于其所在的实际帧。我增加了滚动区域,并且滚动条也正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM