我正在尝试在 tkinter 中开发一个学校应用程序。我正在为应用程序中的每个选项卡创建一个框架。我在代码中包含了我的选项卡作为页面。我为每个选项卡创建了 UI。单独运行时效果很好。
我试图通过堆叠框架来组合它。
我没有错误,但应用程序中与“主页”对应的 tkinter 框架未加载。
感谢任何帮助。
class SchoolApp(tk.Tk):
def __init__(self,*args, **kwargs):
super().__init__(*args, **kwargs)
self.geometry("1500x750")
main_frame = tk.Frame(self,width=200,height=50,highlightbackground="black",highlightthickness=1)
main_frame.pack(side='top', fill='both', expand='True')
main_frame.grid_rowconfigure(0, weight=1)
main_frame.grid_columnconfigure(0, weight=1)
self.frames = {}
pages = (Home,HomePage,LogIn,AdminPage,StaffPage,AdminAddStaff,AdminRemoveStaff,AdminSelectStaff,AdminSearchStaff,AdminUpdateStaff,StaffAddDetails,StaffDisplyDetails)
for F in pages:
frame = F(main_frame, self)
self.frames[F] = frame
frame.pack()
class BasePage(tk.Frame):
def __init__(self, parent, controller):
super().__init__(parent)
#label_bkgr = tk.Label(self, image=controller.bkgr_image)
#label_bkgr.place(x=0,y=0) # Center label w/image.
pass
class Home(BasePage):
def __init__(self,parent,controller):
super().__init__(parent, controller)
home_frame = tk.Frame(self, width=200, height=50, highlightbackground="black", highlightthickness=1)
home_frame.pack(side='top', fill='both', expand='True')
p1 = tk.PanedWindow(home_frame, orient='horizontal', bd=4, relief='raised', bg='#595959', width=1500)
p1.pack()
home = tk.Button(p1, text='Home', height=1, width=15, font=("Helvetica", 15), anchor='center')
p1.add(home)
about = tk.Button(p1, text='About Us', height=1, width=15, font=("Helvetica", 15), anchor='center')
p1.add(about)
academic = tk.Button(p1, text='Academic', height=1, width=15, font=("Helvetica", 15), anchor='center')
p1.add(academic)
facilities = tk.Button(p1, text='Facilities', height=1, width=15, font=("Helvetica", 15), anchor='center')
p1.add(facilities)
student_life = tk.Button(p1, text='Student Life', height=1, width=15, font=("Helvetica", 15), anchor='center')
p1.add(student_life)
contact = tk.Button(p1, text='Contact', height=1, width=15, font=("Helvetica", 15), anchor='center')
p1.add(contact)
admin_portal = tk.Button(p1, text='Admin Portal', height=1, width=15, font=("Helvetica", 15), anchor='center')
p1.add(admin_portal)
staff_portal = tk.Button(p1, text='Staff Portal', height=1, width=15, font=("Helvetica", 15), anchor='center')
p1.add(staff_portal)
l = tk.Label(home_frame, text="Fact of the Day")
l.pack()
T = tk.Text(home_frame, height=5, width=52, font='Arial')
T.pack()
Fact = """A man can be arrested in Italy for wearing a skirt in public."""
T.insert(tk.END, Fact)
def show_frame(self,container):
frame = self.frames[container]
frame.tkraise()