我一直在玩这个示例代码只是尝试不同的东西。我认为布莱恩奥克利最初是这样写的。鉴于此示例代码,如何将灰色区域(我认为是窗口背景)更改为黑色?在我看来,窗口使用的是标准窗口颜色的灰色。我已经更改了每个Frame,试图找出每个区域以及它们的显示方式。我还添加了根背景标签,没有运气。这让我有点疯狂。
import Tkinter as tk
from Tkinter import *
class Page(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
def show(self):
self.lift()
class Page1(Page):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
newframe = tk.Frame(self, width=780, height=540, background="red")
newframe.place(anchor="c", relx=.5, rely=.5)
class Page2(Page):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
newframe = tk.Frame(self, width=780, height=540, background="blue")
newframe.place(anchor="c", relx=.5, rely=.5)
class MainView(tk.Frame):
def __init__(self, *args, **kwargs):
tk.Frame.__init__(self, *args, **kwargs)
p1 = Page1(self)
p2 = Page2(self)
buttonframe = tk.Frame(self, bg='green')
container = tk.Frame(self, bg='yellow')
buttonframe.pack(side="top", fill="x", expand=False)
container.pack(side="top", fill="both", expand=True)
p1.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
p2.place(in_=container, x=0, y=0, relwidth=1, relheight=1)
self.b1 = tk.Button(buttonframe, text="Page 1", command=lambda: p1.lift())
self.b1.pack(side="left")
self.b2 = tk.Button(buttonframe, text="Page 2", command=lambda: p2.lift())
self.b2.pack(side="left")
p1.show()
if __name__ == "__main__":
root = tk.Tk()
main = MainView(root)
root.configure(bg='black')
main.pack(side="top", fill="both", expand=True)
root.wm_geometry("800x600")
root.mainloop()
答案 0 :(得分:0)
我不知道为什么会这样,但这就是我所做的。在MainView内部将两个p1,p2代码更改为以下内容。
p1 = Page1(self, bg='black')
p2 = Page2(self, bg='black')