我在向 tkinter 框架中添加文本框时遇到问题,我可以显示标签,但无法显示文本框

时间:2021-04-29 21:15:55

标签: python tkinter tkinter-entry

在我的注册页面类下面,我添加了所有必要的标签,但没有显示文本框,我将其命名为 nameText。

其他一切正常,该程序的目的是将姓名、姓氏、年龄、单元号和学位名称添加到数据库中。我决定先完成 GUI,然后从那里开始处理后端。


    from tkinter import *
    import tkinter as tk
    
    
    class Students (tk.Tk):
        def __init__ (self, *args, **kwargs):
            tk.Tk.__init__(self, *args, **kwargs)
            container = tk.Frame (self)
            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 (displayMainMenu, RegisterPAGE, viewPage):
                frame = F (container, self)
                self.frames[F] = frame
                frame.grid(row = 0, column = 0, sticky = "nsew")
            self.show_frame(displayMainMenu)
            
        def show_frame (self, cont):
            frame = self.frames[cont]
            frame.tkraise()
            
            
    class displayMainMenu (tk.Frame):
        def __init__ (self, parent, controller):
            tk.Frame.__init__ (self, parent)
            label = tk.Label(self, text = "MENU")
            label.pack(pady = 10, padx = 10)
            
            registerButton = tk.Button(self, text = "Register Student", command=lambda: controller.show_frame(RegisterPAGE))
            registerButton.pack()
            viewButton = tk.Button(self, text = "View Registered Student", command=lambda: controller.show_frame(viewPage))
            viewButton.pack()
            exitButton = tk.Button(self, text = "EXIT", command=lambda: controller.show_frame(RegisterPage))
            exitButton.pack()
            
    class RegisterPAGE (tk.Frame):
    
       def __init__(self, parent, controller):
        tk.Frame. __init__(self, parent)
        
        label = tk.Label(self, text = "Student name")
        label.pack(pady = 10, padx = 10)
        nameText = tk.Entry(self, bd=5)
        label.pack(pady = 10, padx = 10)
        label = tk.Label(self, text = "Student surname")
        label.pack(pady = 10, padx = 10)
        label = tk.Label(self, text = "Student age")
        label.pack(pady = 10, padx = 10)
        label = tk.Label(self, text = "Student cell phone number")
        label.pack(pady = 10, padx = 10)
        label = tk.Label(self, text = "Which degree do you want to study:")
        label.pack(pady = 10, padx = 10)
        
        backButton = tk.Button(self, text = "Back", command=lambda: controller.show_frame(displayMainMenu))
        backButton.pack()
        
     
    class viewPage (tk.Frame):
    
       def __init__(self, parent, controller):
        tk.Frame. __init__(self, parent)
        label = tk.Label(self, text = "View Registered Students")
        label.pack(pady = 10, padx = 10)
        
        backButton = tk.Button(self, text = "Back", command=lambda: controller.show_frame(displayMainMenu))
        backButton.pack()
        
            
    app = Students ()
    app.mainloop()

1 个答案:

答案 0 :(得分:1)

好像您没有打包条目。

    nameText.pack(pady = x, padx = y)