我一直在尝试创建一个名为vwin的类,它可以创建 Tk 或 Toplevel 窗口。不幸的是,它返回一个错误:
Traceback (most recent call last):
File "C:\Users\RELIC\Desktop\textpad.py", line 17, in <module>
sub = vwin(['Sub Window','640x480-25-25','normal','window'],root)
File "C:\Users\RELIC\Desktop\textpad.py", line 9, in __init__
window = Toplevel(master)
File "C:\Python33\lib\tkinter\__init__.py", line 2136, in __init__
BaseWidget.__init__(self, master, 'toplevel', cnf, {}, extra)
File "C:\Python33\lib\tkinter\__init__.py", line 2086, in __init__
BaseWidget._setup(self, master, cnf)
File "C:\Python33\lib\tkinter\__init__.py", line 2064, in _setup
self.tk = master.tk
AttributeError: 'vwin' object has no attribute 'tk'
这是我的代码:
###############################################################################
from tkinter import *
class vwin():
def __init__(self,args,master=None):
if args[3].lower() == 'tk':
window = Tk()
else:
window = Toplevel(master)
window.title(args[0])
window.geometry(args[1])
window.state(args[2])
root = vwin(['Main Window','640x480+25+25','normal','Tk'])
sub = vwin(['Sub Window','640x480-25-25','normal','window'],root)