tkinter - 滚动条不会显示

时间:2017-07-05 17:40:11

标签: python tkinter

我正在使用Python开发GUI,并且没有滚动条显示我何时运行它。它有一个带箭头的空条,但里面没有滚动条,滚动条根本不起作用。

#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)

1 个答案:

答案 0 :(得分:0)

我的滚动区域需要比它所在的实际框架大。我增加了滚动区域,滚动条也有效。