简体   繁体   中英

I'm having trouble adding a text box to my tkinter frame, I can get labels to show up but I can't get the text box to show

Underneath my Register page class I added all the necessary labels but the text box doesn't show up I called it nameText.

Everything else works fine, the purpose of this program is to add the name, surname, age, cell number and the degree name to a database. I've decided to finish the GUI first and then work on the back end from there.


    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()

It seems like you didn't pack the entry.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM