class - python non-existing argument taken -
yeah, i've overcame problems wrong execution order, you, have more of them.
xcv.py (former welcome.py)
#!/usr/bin/env python2.7 #-*- encoding: utf-8 -* 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 brunhilda gui alpha v0.0',0,0,self) widgets().newlabel(u'what want 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()
definitions.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()
when widget or action called out, keeps on telling me being given arguments
typeerror: newlabel() takes 4 arguments (5 given)
also, have done terrible job definition classes, suppose, have no idea how make them better
- edit okay, now. forgot should add "self" definitions in class. closed
self
parameter represents instance of class, , first parameter function called instance of class.
say have class a
class a: def b(self): print "hello"
to call function b, first need create instance of a
>>> my_a = a() >>> my_a.b() hello
now might wondering.. "why a.b() work if there no self
parameter given?"
this because when call function instance of class, automatically places instance first parameter!
to make more sense can think of (which work)..
>>> my_a = a() >>> a.b(my_a) hello
Comments
Post a Comment