【发布时间】:2014-05-28 21:34:56
【问题描述】:
是的,所以我已经克服了执行顺序错误的问题,多亏了你,但我还有更多。
xcv.py(以前的welcome.py)
#!/usr/bin/env python2.7
#-*- encoding: utf-8 -*
from definitions import *
def NewLabel(text, column, row, self):
label=Label(self, text=text)
label.grid(column=column,row=row)
def NewButton(text, action, column, row, self, sticky="N"):
button=Button(self, text=text, command=action)
button.grid(column=column,row=row,sticky=sticky)
def OnExit():
quit()
class encode(Tk):
def __init__(self,parent):
Tk.__init__(self,parent)
self.parent=parent
self.initialize()
def initialize(self):
widgets().NewLabel(u'Welcome to Brunhilda GUI alpha v0.0',0,0,self)
widgets().NewLabel(u'What do you want to do?',0,1,self)
# widgets().NewButton(u'1. Encrypt file',OnEncode(None),0,2,self)
# widgets().NewButton(u'2. Decrypt file',OnDecode,0,3,self)
# widgets().NewButton(u'Exit',actions().OnExit(),0,4,self)
if __name__=="__main__":
app=encode(None)
app.title('Brunhilda GUI v0.0 encoder')
app.mainloop()
定义.py
from Tkinter import *
import decoding
import encoding
import zxc
version="v0.0"
class widgets():
def NewLabel(text, column, row, self):
label=Label(self, text=text)
label.grid(column=column,row=row)
def NewEntry(self, text, column, row, action, key='<Return>', sticky="EW"):
entry=Entry(self, textvariable=StringVar())
entry.grid(column=column, row=row, sticky=sticky)
entry.bind(key, action)
StringVar().set(text)
def NewButton(text, action, column, row, self, sticky="N"):
button=Button(self, text=text, command=action)
button.grid(column=column,row=row,sticky=sticky)
print asdf
class actions():
def OnEncode(self):
try:
zxc.encode(self)
quit()
except KeyboardInterrupt:
print "goodbye"
quit()
def OnDecode():
try:
decoding.decode(version)
except KeyboardInterrupt:
print "Goodbye"
quit()
def OnExit():
quit()
当调用任何小部件或操作时,它会不断告诉我它被赋予了太多参数
TypeError: NewLabel() takes exactly 4 arguments (5 given)
另外,我想我在定义类方面做得很糟糕,但我不知道如何让它们更好
- 编辑 好的,我现在明白了。我忘了我应该在课堂上的定义中添加“自我”。 关闭
【问题讨论】:
-
您忘记将
self命名为NewLabel()的参数。 -
NewLabel确实有一个self参数。这不是第一个。 (也许您应该将其重命名为master或其他名称,因为这样更具描述性) -
与您的问题无关,您使用的
StringVar错误。您正在创建一个StringVar以与一个条目关联,但随后创建了第二个StringVar,它没有被使用。你需要创建一个StringVar。
标签: python class arguments typeerror