简体   繁体   English

tkinter-滚动条将不会显示

[英]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. 我正在用Python开发一个GUI,运行时没有滚动条显示。 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)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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