Python 添加到主帧的帧未在Tkinter中显示

Python 添加到主帧的帧未在Tkinter中显示,python,tkinter,Python,Tkinter,我正在尝试使用tkinter创建一个学校应用程序。我需要显示数据库中的详细信息 该应用程序有两个页面“StaffPage”和“StaffDisplayDetails”。我已经创建了这两个页面作为框架,并将它们堆叠起来以显示它们。它工作得很好 但是当我想显示数据库中的数据时,框架没有显示出来 这是我的密码。感谢您的帮助 import tkinter as tk from tkinter import ttk import mysql.connector from tkcalendar import

我正在尝试使用tkinter创建一个学校应用程序。我需要显示数据库中的详细信息

该应用程序有两个页面“StaffPage”和“StaffDisplayDetails”。我已经创建了这两个页面作为框架,并将它们堆叠起来以显示它们。它工作得很好

但是当我想显示数据库中的数据时,框架没有显示出来

这是我的密码。感谢您的帮助

import tkinter as tk
from tkinter import ttk
import mysql.connector
from tkcalendar import *
import datetime
from tkinter import *

class SchoolApp(tk.Tk):

    #BKGR_IMAGE_PATH = 'images\\bg11.png'

    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,background='white')
        main_frame.pack(side='top', fill='both', expand='True')

        main_frame.grid_rowconfigure(0, weight=1)
        main_frame.grid_columnconfigure(0, weight=1)

        #self.bkgr_image = tk.PhotoImage(file=self.BKGR_IMAGE_PATH)

        self.frames = {}
        pages = (StaffPage,StaffDisplyDetails)
        for F in pages:
            frame = F(main_frame, self)
            self.frames[F] = frame
            frame.grid(row=0, column=0, sticky='nsew')

        self.show_frame(StaffPage)


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

class BasePage(tk.Frame):

    def __init__(self, parent, controller):
        super().__init__(parent)

class StaffPage(BasePage):

    def __init__(self,parent,controller):

        super().__init__(parent, controller)


        main_frame = tk.Frame(self, width=200, height=100, highlightbackground="black", highlightthickness=1,
                              bg='white')
        # main_frame.grid(row=0, column=0, sticky='nsew')
        main_frame.pack(side='top', fill='both', expand='True')

        # main_frame.grid_rowconfigure(0, weight=1)
        # main_frame.grid_columnconfigure(0, weight=1)

        p1 = tk.PanedWindow(main_frame, orient='horizontal', bd=4, relief='raised', bg='#595959', width=1500)
        p1.grid(row=0, column=0, sticky='w')
        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)

        staff_window = tk.Frame(main_frame, width=200, height=100, background="white",highlightbackground="green",highlightthickness=1)
        staff_window.grid(row=10, column=0, padx=10, pady=100)

        self.label_title_staff = tk.Label(staff_window, text="Staff Dashboard", font=("Helvetica", 40), bg="white")
        self.label_title_staff.grid(row=0, column=0, padx=10, pady=10, sticky='W')

        self.staff_logout_button = tk.Button(staff_window, text="Logout", width=15, font=("Helvetica", 12), bg="#6699ff")
        self.staff_logout_button.grid(row=0, column=20, sticky='E', padx=20)

        staff_frame = tk.Frame(staff_window, width=200, height=150, highlightbackground="black", highlightthickness=1,bg="white")
        staff_frame.grid(row=30, column=0, padx=25, pady=50)

        staff_calendar_frame = tk.Frame(staff_window, width=200, height=100, highlightbackground="black",highlightthickness=1)
        staff_calendar_frame.grid(row=30, column=20, padx=20, pady=20)

        self.today = datetime.datetime.now()

        self.calendar_variable = Calendar(staff_calendar_frame, selectmode="day", year=self.today.year, month=self.today.month,day=self.today.day)
        self.calendar_variable.grid(row=0, column=0)

        staff_register = tk.Frame(staff_frame, width=100, height=50)
        staff_register.grid(row=0, column=0, padx=50, pady=50)

        self.register_Image = tk.PhotoImage(file="images\\register1.png")
        self.register_Image_Pack = tk.Label(staff_register, image=self.register_Image)
        self.register_Image_Pack.grid()

        self.register_staff_button = tk.Button(staff_frame, text="Add Details", width=15, font=("Helvetica", 12))
        self.register_staff_button.grid(row=60, column=0, pady=20)

        staff_display = tk.Frame(staff_frame, width=100, height=50)
        staff_display.grid(row=0, column=30, padx=50, pady=50)

        self.staff_display_Image = tk.PhotoImage(file="images\\display1.png")
        self.staff_display_Image_Pack = tk.Label(staff_display, image=self.staff_display_Image)
        self.staff_display_Image_Pack.grid()

        self.display_staff_button = tk.Button(staff_frame, text="Display Details", width=15, font=("Helvetica", 12),command = lambda:controller.show_frame(StaffDisplyDetails))
        self.display_staff_button.grid(row=60, column=30, pady=20)

class StaffDisplyDetails(BasePage):

    def __init__(self,parent,controller):

        super().__init__(parent, controller)

        main_frame = tk.Frame(self, width=200, height=100, highlightbackground="black", highlightthickness=1,
                              bg='white')
        main_frame.grid(row=0, column=0, sticky='nsew')
        #main_frame.pack(side='top', fill='both', expand='True')

        # main_frame.grid_rowconfigure(0, weight=1)
        # main_frame.grid_columnconfigure(0, weight=1)

        p1 = tk.PanedWindow(main_frame, orient='horizontal', bd=4, relief='raised', bg='#595959', width=1500)
        p1.grid(row=0, column=0, sticky='w')
        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)

        staff_window = tk.Frame(main_frame, width=200, height=100, background="white",highlightbackground="green",highlightthickness=1)
        staff_window.grid(row=10, column=0, padx=10, pady=180)


        self.label_title_staff = tk.Label(staff_window, text="Staff Dashboard", font=("Helvetica", 40), bg="white")
        self.label_title_staff.grid(row=0, column=0, padx=10, pady=10, sticky='W')

        self.staff_back_button = tk.Button(staff_window, text="Back", width=15, font=("Helvetica", 12), bg="#6699ff")
        self.staff_back_button.grid(row=0, column=10, sticky='E', padx=20)

        staff_frame = tk.Frame(staff_window, width=200, height=150, highlightbackground="black", highlightthickness=1,bg="white")
        staff_frame.grid(row=30, column=0, padx=25, pady=50)

        self.label_staff_id = tk.Label(staff_frame, text="Staff Id", font=("Helvetica", 20), bg="white")
        self.label_staff_id.grid(row=20, column=20, padx=10, pady=10, sticky='W')
        self.entry_staffid = tk.Entry(staff_frame, width=20, font=("Helvetica", 20), bd=3)
        self.entry_staffid.grid(row=20, column=30, padx=10, pady=10)

        self.search_staff_button = tk.Button(staff_frame, text="Search", width=8, font=("Helvetica", 20), bg="white",command=lambda: search_class())
        self.search_staff_button.grid(row=30, column=25, padx=10, pady=10)

        staff_calendar_frame = tk.Frame(staff_window, width=200, height=100, highlightbackground="black",highlightthickness=1)
        staff_calendar_frame.grid(row=30, column=10, padx=10, pady=20)

        self.today = datetime.datetime.now()

        self.calendar_variable = Calendar(staff_calendar_frame, selectmode="day", year=self.today.year, month=self.today.month,day=self.today.day)
        self.calendar_variable.grid(row=0, column=0)

        def search_class():

            staff_window.grid_forget()

            self.id = self.entry_staffid.get()
            print(self.id)

            query = "SELECT * FROM staff_schedule WHERE staff_id = '" + self.id + "'"
            # print(query)

            staff = mysql.connector.connect(host="localhost", user="root", password="", database="school_database")
            cursor_variable = staff.cursor()
            cursor_variable.execute(query)


            staff_window1 = tk.Frame(main_frame, width=200, height=100, background="white")
            staff_window1.grid(row=50, column=150, padx=200, pady=150)

            self.label_title_staff = tk.Label(staff_window1, text="Staff Dashboard", font=("Helvetica", 40), bg="white")
            self.label_title_staff.grid(row=0, column=0, padx=10, pady=10, sticky='W')

            self.staff_back_button = tk.Button(staff_window1, text="Back", width=15, font=("Helvetica", 12), bg="#6699ff")
            self.staff_back_button.grid(row=0, column=10, sticky='E', padx=20)

            staff_frame = tk.Frame(staff_window1, width=200, height=150, highlightbackground="black",highlightthickness=1, bg="white")
            staff_frame.grid(row=30, column=0, padx=25, pady=50)

            staff_calendar_frame = tk.Frame(staff_window1, width=200, height=100, highlightbackground="black",highlightthickness=1)
            staff_calendar_frame.grid(row=30, column=10, padx=10, pady=20)

            self.today = datetime.datetime.now()

            self.calendar_variable = Calendar(staff_calendar_frame, selectmode="day", year=self.today.year, month=self.today.month,day=self.today.day)
            self.calendar_variable.grid(row=0, column=0)

            self.vertical_scrollbar = ttk.Scrollbar(staff_frame)
            self.vertical_scrollbar.pack(side=RIGHT, fill=Y)

            self.my_tree = ttk.Treeview(staff_frame, yscrollcommand=self.vertical_scrollbar.set)
            self.my_tree.pack()

            self.vertical_scrollbar.config(command=self.my_tree.yview)

            style = ttk.Style(staff_frame)
            style.theme_use("winnative")
            style.configure(".", font=("Helvetica", 11))
            style.configure("Treeview.Heading", font=("Helvetica", 11, "bold"))

            self.my_tree['columns'] = ("staff_id", "subject_allotted", "class_name", "time_allotted")
            self.my_tree.column("#0", width=0, stretch='NO')
            self.my_tree.column("staff_id", width=50, anchor='w')
            self.my_tree.column("subject_allotted", width=130, anchor='w')
            self.my_tree.column("class_name", width=130, anchor='w')
            self.my_tree.column("time_allotted", width=100, anchor='w')

            self.my_tree.heading("#0", anchor='w', text='Label')
            self.my_tree.heading("staff_id", anchor='w', text="Id")
            self.my_tree.heading("subject_allotted", anchor='w', text="Subject")
            self.my_tree.heading("class_name", anchor='w', text="Class")
            self.my_tree.heading("time_allotted", anchor='w', text="Time")

            count = 0

            for record in cursor_variable:
                # print(record)
                self.my_tree.insert(parent='', index='end', iid=count, text='Parent',values=(record[0], record[1], record[2], record[3]))
                count += 1

            staff.close()

app = SchoolApp()
app.mainloop()

您发布的代码远远超过了重现问题所需的代码。请看。您的意思是
职员\u window1
?您将
staff\u window1
放在最右侧(
column=150
),可能在窗口的可见区域之外。@acw1668谢谢您,它成功了