我的代码根本不会在每次尝试打开它时都运行,所以我认为框架混乱了。为什么会这样?
我在网上一直遵循很多指南,它们有类似的代码,但我的代码仍然很混乱。
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()
我希望我的代码随登录页面一起弹出,显示一些文本,但是什么都不会弹出。
答案 0 :(得分:0)
您收到错误消息。
您在
中有变量arg1
,arg2
class OwlEyes(tk.Tk):
def __init__(self, arg1, arg2):
tk.Tk.__init__(self, arg1, arg2)
但是您没有值
root = OwlEyes()
如果您删除arg1
,arg2
,则会启动
class OwlEyes(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)