简体   繁体   中英

Why does my tkinter code with multiple frames not even run

My code simply doesn't run every time I try to open it so I believe the frames are messed up. Why is this?

I've followed a lot of guides online and they had similar code yet my code still messes up.

import tkinter as tk       

LABEL_FONT = ('Helvetica', 10)

class OwlEyes(tk.Tk):
    def __init__(self, arg1, arg2):
        tk.Tk.__init__(self, arg1, arg2)
        self.frames = {}

        container = tk.Frame(self, bg = 'black')            
        container.pack(side = "top", fill = "both", expand = True) 
        container.grid_columnconfigure(0, weight = 1)
        container.grid_rowconfigure(0, weight = 1)

        frame = LoginPage(container, self)
        self.frames[LoginPage] = frame

        frame.grid(row = 0, column = 0, sticky = "nsew")

        self.show_frame(LoginPage)

    def show_frame(self, cont):
        frame = self.frames[cont]
        frame.tkraise()
class LoginPage(tk.Frame):
    def __init__(self, parent, controller):
        tk.Frame.__init__(self, parent)
        labelUser = tk.Label(self, text = "Username:", font = LABEL_FONT, bg = 'black', fg = '#15F4EE')             
        labelUser.pack(pady = 10, padx = 10)    
        button1 = tk.Button(self, text='Back to Home')
        button1.pack()


root = OwlEyes()
root.mainloop()

I expect my code to just pop up with the Login page, showing some text, but nothing even pops up.

You get error message.

You has variables arg1 , arg2 in

class OwlEyes(tk.Tk):
    def __init__(self, arg1, arg2):
        tk.Tk.__init__(self, arg1, arg2)

but you run without values

root = OwlEyes()

If you remove arg1 , arg2 then it starts

class OwlEyes(tk.Tk):
    def __init__(self):
        tk.Tk.__init__(self)

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