1
我一直在試圖做一個類,名爲vwin它使Tk或Toplevel窗口。不幸的是它返回一個錯誤:Tkinter自定義類錯誤
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)
它的工作原理,非常感謝你。 –