[ wraith46 @ 01.04.2017. 09:50 ] @
Pravim jednostavan GUI program (nešto kao To Do List), imam problem sa addovanjem itema u listbox. U svom programu imam klasu Priority, te sam pokušao da napravim instancu te klase i da u konstruktoru prosledim atribute subject i priority, pa da ceo taj item dodam u listbox. Međutim, dobijam error: Citat: /usr/bin/python3.5 /home/cali/PycharmProjects/priorities/priorities.py Exception in Tkinter callback Traceback (most recent call last): File "/usr/lib/python3.5/tkinter/__init__.py", line 1553, in __call__ return self.func(*args) File "/home/cali/PycharmProjects/priorities/priorities.py", line 52, in addItem item = Priority(subject = g.textBox.get("1.0", 'end-1c'), priority = g.textBox.get("1.0", 'end-1c')) AttributeError: 'GuiPart' object has no attribute 'textBox' Evo šta sam uradio: Code: # priorities.py # GUI program to manage priorities from tkinter import * class Priority: def __init__(self, subject, priority): self.subject = subject self.priority = priority def subject(self): return self.subject def priority(self): return self.priority class GuiPart: def __init__(self): self.root = self.createWindow() def createWindow(self): root = Tk() root.resizable(width = False, height = False) root.title("Priorities") return root def createWidgets(self): Button(self.root, text = "Add", command = self.addItem).grid(row = 2, column = 0, sticky = W + E) Button(self.root, text="Remove", command = self.removeItem).grid(row = 2, column = 1, sticky = W + E) Button(self.root, text="Edit", command = self.editItem).grid(row = 2, column = 2, sticky = W + E) listBox = Listbox(width = 30).grid(row = 1, sticky = W + E, columnspan = 3) textBox = Text(height=5, width=30).grid(row = 3, columnspan = 3, sticky = W + E + N + S) def addItem(self): item = Priority(subject = g.textBox.get("1.0", 'end-1c'), priority = g.textBox.get("1.0", 'end-1c')) g.listBox.insert(END, item) def removeItem(self): pass def editItem(self): pass class Client: pass if __name__ == "__main__": g = GuiPart() g.createWidgets() g.root.mainloop() |