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