Python 3.4 Tkinter - Object has no attribute -
i'm making program kind of simulate console. code far (i started today, learning tkinter, although i'm not sure if tkinter best choice):
from tkinter import * class app: def __init__(self, master): self.frame = frame(master, bg = 'black') self.bottomframe = frame(master, bg = 'black') self.elabel = label(master, text = '>', bg = 'black', font = 'system', fg = 'white') self.einput = entry(master, bd =0, bg = 'black', font = 'system', fg = 'white', command = self.update_text()) # packing self.frame.pack() self.bottomframe.pack(side = bottom) self.elabel.pack(side = left) self.einput.pack(side = left) def update_text(self): self.einput.insert(0, '>') root = tk() app = app(root) root.mainloop()
the error is
traceback (most recent call last): file "c:/users/*/pycharmprojects/consoledungeon/game.py", line 21, in <module> app = game(root) file "c:/users/*/pycharmprojects/consoledungeon/game.py", line 9, in __init__ self.einput = entry(master, bd =0, bg = 'black', font = 'system', fg = 'white', command = self.update_text()) file "c:/users/*/pycharmprojects/consoledungeon/game.py", line 17, in update_text self.einput.insert(0, '>') attributeerror: 'game' object has no attribute 'einput'
and 1 more thing: in line
self.einput = entry(master, bd =0, bg = 'black', font = 'system', fg = 'white', command = self.update_text())
i wasn't sure how use command argument.
i'm not sure command
argument supposed on entry
widget, that's problem lives alright. command
expects callable (that is, function name, not calling of function). way program flows right is:
create app make app.frame make app.bottomframe make app.elabel make app.einput --> oh, there's function call in declaration, gotta follow before finish making object ------> function call refers `app.einput`, don't have 1 of (yet!) better throw attributeerror
Comments
Post a Comment