为背景TKinter框架着色

时间:2019-02-03 15:45:20

标签: python tkinter

我正在尝试为Tkinter框架(工具栏)着色,由于某种原因,它不起作用。我试图在Frame构造函数中添加background参数,但这不起作用。 在下面的代码中,我在所有类的构造函数中添加了background参数,但不适用于Toolbar类。对于其他类,它确实起作用。谁能告诉我我在这里想念的东西吗?

谢谢。

代码:

from tkinter import *
from App.Configuration import Configuration as cfg


class App(Tk):
    def __init__(self, *args, **kwargs):
        Tk.__init__(self, *args, **kwargs)
        # Setup Menu
        MainMenu(self)
        # Setup Frame
        container = Frame(self)
        container.grid(row=1, column=0)

        toolbar_frame = Toolbar(container, self)
        toolbar_frame.grid(row=0, column=0)

        self.frames = {}

        for F in (StartPage, PageOne, PageTwo):
            frame = F(container, self)
            self.frames[F] = frame
            frame.grid(row=2, column=0)

        self.show_frame(StartPage)

    def show_frame(self, context):
        frame = self.frames[context]
        frame.tkraise()


class StartPage(Frame):
    def __init__(self, parent, controller):
        Frame.__init__(self, parent, bg="blue")


class Toolbar(Frame):
    def __init__(self, parent, controller):
        Frame.__init__(self, parent, bg="blue")

        home_button = Button(controller, text="one", command=doNothing, background=cfg.toolbar_button_background,
                             foreground=cfg.toolbar_button_enabled_text)
        home_button.grid(row=0, column=0)


app = App()
app.mainloop()

0 个答案:

没有答案