简体   繁体   中英

Tkinter button does not appear in the window

I am trying to create a login system in Python. I was able to create the window but the button does not appear therein. Can someone please help me? Here the code:


from tkinter import *



class Window(Frame):
    

    def __init__(self, master = None): 
        
        Frame.__init__(self, master) 
        self.master.title("Login")
        self.pack(fill = BOTH, expand = 1)

        
        self.master = master

    
    def init_window(self):

        self.master.title("Register")
        
        self.pack(fill= BOTH, expand= 1)

        registerbutton = Button(self, text= "Register")
        
        registerbutton.place(x = 0, y = 0)




root = Tk()

root.geometry("400x300")

app = Window(root)

root.mainloop()

You need to call init_window() function, in order to show the button as place is in that function

app = Window(root)
app.init_window()
root.mainloop()

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