Tkinter帆布颜色

时间:2014-04-09 18:25:36

标签: python canvas tkinter

我有这个滚动的框架类:

 class ScrolledFrame(Frame):
    def __init__(self, parent, *args, **kw):
        Frame.__init__(self, parent, *args, **kw)
        # create a canvas object and a vertical scrollbar for scrolling it
        canvas = Canvas(self)
        canvas.config(width = 1000, height = 900)
        vscrollbar = Scrollbar(self, orient=VERTICAL,command=canvas.yview)
        vscrollbar.pack(fill=Y, side=RIGHT)
        hscrollbar = Scrollbar(self, orient=HORIZONTAL,command=canvas.xview)
        hscrollbar.pack(fill=X, side=BOTTOM)
        canvas.configure(yscrollcommand=vscrollbar.set)
        canvas.configure(xscrollcommand=hscrollbar.set)
        canvas.pack(side=LEFT, fill=BOTH, expand=TRUE)

        # reset the view
        canvas.xview_moveto(0)
        canvas.yview_moveto(0)

        # create a frame inside the canvas which will be scrolled with it
        self.interior = interior = Frame(canvas)
        interior_id = canvas.create_window(0, 0, window=interior,
                                           anchor=NW)

        # track changes to the canvas and frame width and sync them,
        # also updating the scrollbar
        def _configure_interior(event):
            # update the scrollbars to match the size of the inner frame
            size = (interior.winfo_reqwidth(), interior.winfo_reqheight())
            canvas.config(scrollregion="0 0 %s %s" % size)
            if interior.winfo_reqwidth() != canvas.winfo_width():
                # update the canvas's width to fit the inner frame
                canvas.config(width=interior.winfo_reqwidth())
        interior.bind('<Configure>', _configure_interior)

我在我的应用程序中这样称呼它:

class Application(Frame):
  self.root() = Tk()

....之后的通常代码。

  self.frame = ScrolledFrame(self.root)
  self.frame.pack()

  self.statusFrame = Frame(self.frame.interior,borderwidth = 1)
  self.statusFrame.pack(side = TOP, fill = X)

我在ScrolledFrame类和self.frame.interior.config(bg ='black')中尝试过canvas.config(bg ='black'),但画布的颜色没有变化。如何更改背景颜色?

谢谢!

0 个答案:

没有答案