如何在tkinter中为帧添加背景色

时间:2019-05-31 15:32:40

标签: tkinter python-3.7

这是我程序的简化版本,希望您能解决该问题,因为它仍然对我不起作用。我已经分别尝试过此代码,并且背景色仍然没有显示

    from tkinter import *

    import tkinter as tk


    class APP(tk.Tk):
        def __init__(self, *args, **kwargs):
            tk.Tk.__init__(self, *args, **kwargs)
            container= tk.Frame(self, bg="#1F2833")
            container.config(background="#1F2833")
            container.pack(side="top", fill="both", expand=True)
            container.grid_rowconfigure(0, weight=1)
            container.grid_columnconfigure(0, weight=1)
            self.frames = {}

            for f in (HomePage, TopicPage, AboutPage):
                frame = f(container, self)
                self.frames[f]= frame
                frame.grid(row=0, column=0, sticky="nsew")


class HomePage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        button = tk.Button(self, text="Topics")

class TopicPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        button = tk.Button(self, text="Home")

class AboutPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        button = tk.Button(self, text="Home")

app = APP()
app.geometry("900x600")
app.resizable(0, 0)
app.mainloop()

0 个答案:

没有答案