python - AttributeError: 'Vocabulary' object has no attribute 'listBox' -


i creating vocabulary, gui program manage unknown words. getting:

/usr/bin/python3.5 /home/cali/pycharmprojects/vocabulary/vocabulary.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/vocabulary/vocabulary.py", line 86, in add_item self.listbox.insert(end, self.get_word()) attributeerror: 'vocabulary' object has no attribute 'listbox'

process finished exit code 0

... when try add item listbox.

here have done:

#!/usr/bin/env python  # vocabulary.py #   gui program manage unknown words  tkinter import *  class word:      def __init__(self, wordorphrase, explanation, translation, example):         self.wordorphrase = wordorphrase         self.explanation = explanation         self.translation = translation         self.example = example  class vocabulary(frame):      def __init__(self, master):         frame.__init__(self, master)         self.master = master         self.master.resizable(width = false, height = false)         self.master.title("vocabulary")         self.create_widgets()      def create_widgets(self):          lblwordsorphrases = label(self.master, text = 'words or phrases:')         lblwordsorphrases.grid(row = 0, column = 0)          lblwordorphrase = label(self.master, text = 'word or phrase:')         lblwordorphrase.grid(row = 0, column = 1, sticky = w)          listbox = listbox(self.master,                           height = 34,                           width = 30)         listbox.grid(row = 1, column = 0, rowspan = 7)          txt_wordorphrase = text(self.master,                                 height = 1,                                 width = 40)         txt_wordorphrase.grid(row = 1, column = 1, sticky = n)          lblexplanation = label(self.master, text = 'explanation:')         lblexplanation.grid(row = 2, column = 1, sticky = w)          txt_explanation = text(self.master,                                height = 10,                                width = 40)         txt_explanation.grid(row = 3, column = 1, sticky = n)          lbltranslation = label(self.master, text = 'translation:')         lbltranslation.grid(row = 4, column = 1, sticky = w)          txt_explanation = text(self.master,                                height = 10,                                width = 40)         txt_explanation.grid(row = 5, column = 1, sticky = n)           lblexamples = label(self.master, text = 'example(s):')         lblexamples.grid(row = 6, column = 1, sticky = w)          txt_explanation = text(self.master,                                height = 10,                                width = 40)         txt_explanation.grid(row = 7, column = 1, sticky = s)          btn_add = button(self.master,                          text = 'add',                          command = self.add_item)         btn_add.grid(row = 8, column = 0, sticky = w)      def get_word(self):         return self.txt_wordorphrase.get('1.0', '1.0 lineend')      def get_explanation(self):         return self.txt_explanation.get('1.0', '1.0 lineend')      def get_translation(self):         return self.txt_translation.get('1.0', '1.0 lineend')      def get_example(self):         return self.txt_example.get('1.0', '1.0 lineend')      def add_item(self):         self.listbox.insert(end, self.get_word())  def main():     root = tk()     vocabulary(root)     root.mainloop()  if __name__ == '__main__':     main() 

i'm using python 3.5.

you listbox variable local create_widgets since not set self. in order make variable available instance-wide, need contain in self.

change line in create_widgets self.listbox = listbox(self.master, height = 34, width = 30) , change every reference listbox self.listbox in order apply change.

you might want defined self.listbox in __init__(), might keep track of instance variables.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -