初学者疯狂 - 属性错误:"窗口"对象没有属性"tk"



main.py

from window import *
from toplevel import *
w = Window("Title")
t = Top(w)

window.py

### IMPORT TKINTER
from tkinter import *
## CLASS Window
class Window():
def __init__(self , title):
self.window = Tk()
self.window.title(title)
self.window.mainloop()

顶层.py

### IMPORT 'TKINTER'
from tkinter import *
## CLASS TOP
class Top():
def __init__(self , master):
self.top = Toplevel(master)
self.top.transient(master)
self.top.resizable(0 , 0)
self.top.mainloop()

顶层没有出现,当我关闭";窗口";控制台输出为:AttributeError:"Window"对象没有属性"tk">

有人能帮我吗??非常感谢

您只能将小部件用作其他小部件的父级。您正在使用w(Window的实例(作为在Top中创建的窗口的父级。

您需要Window从tkinter小部件(例如:class Window(Tk)(继承,使其成为小部件,或者您需要传入w.window作为父级(例如:t = Top(w.window)(

最新更新