我正在尝试将两个不同的框架放入我的程序中的两个不同的选项卡中。我怎样才能做到这一点。每次执行程序时,我只会得到一种颜色。似乎frame2覆盖了另一帧。谢谢
from Tkinter import *
from ttk import *
class Application:
def __init__(self, master):
self.create_widgets()
self.trip = {}
self.frameinMaintabA()
def create_widgets(self):
self.notebook = Notebook() # Widgets
self.tabA = Frame(self.notebook)
self.tabB = Frame(self.notebook)
self.tab3 = Frame(self.notebook)
self.mainA = Notebook(self.tabA)
self.tabA1 = Frame(self.mainA)
self.tabA2 = Frame(self.mainA)
self.mainA.add(self.tabA1, text = "tabA1")
self.mainA.add(self.tabA2, text = "tabA2")
self.mainA.pack(fill = 'both', expand = 1, padx = 10, pady = 10)
self.notebook.add(self.tabA, text = "tabA")
self.notebook.add(self.tabB, text= "tabB")
self.notebook.pack(fill = 'both', expand = 1, padx = 10, pady = 10)
def frameinMaintabA(self):
self.style = Style()
self.style.configure('frame.TFrame', background='grey')
self.frame = Frame( self.tabA1,style='frame.TFrame')
self.frame.place(height=40, width=70, x=158, y=109)
self.style2 = Style()
self.style2.configure('frame.TFrame', background='blue')
self.frame2 = Frame( self.tabA2,style='frame.TFrame')
self.frame2.place(height=40, width=70, x=158, y=109)
root = Tk()
root.title("Test")
root.geometry("400x400")
app = Application(root)
root.mainloop()
答案 0 :(得分:1)
别介意,我能弄明白我的错误。 我注意到代码中缺少'frame2.Tframe'
self.style2 = Style()
self.style2.configure('frame2.TFrame', background='blue')
self.frame2 = Frame( self.tabA2,style='frame2.TFrame')
self.frame2.place(height=40, width=70, x=158, y=109)