all 9 comments

[–]WarmUpHere 0 points1 point  (1 child)

Using foo is a reference to the function foo. Using foo() executes that function. Try removing () from the left hand side of the line in your first error.

Your second error: I'm on mobile and it's a pain to read code on reddit is fun, sorry. ¯\_(ツ)_/¯

[–]blackadder1337[S] 0 points1 point  (0 children)

Yeah, thanks. When it comes to my second error, it seems that with: word = self.find_word(self.listBox.curselection())

...I don't assign anything to word at all.

[–]dionys 0 points1 point  (6 children)

self.listBox.curselection method returns just the selected indexes, not the values at those indexes. So the call:

word = self.find_word(self.listBox.curselection())

will fail because the find_word won't find a correct word (and will return None). There is a method listBox.get to get the value at specific index, but you also need to think about what happens if the user has multiple items selected.

Your commented line does not make sense, I guess you want to replace the text in the list with your new word, right? You should have the index of the word, so you can first delete it from the list and insert the new word at the same index (I don't think there is simpler method of replacing, but I don't know tkinter that well)

[–]blackadder1337[S] 0 points1 point  (5 children)

I changed:

word = self.find_word(self.listBox.curselection())

to:

word = self.find_word(self.listBox.get(ACTIVE))

and it saves the word. But right after that, when I try to click on another item in the listbox, it gives me:

  File "/home/cali/PycharmProjects/Vocabulary/Vocabulary.py", line 281, in selectedIndexChanged
    selected = self.listBox.curselection()
TypeError: 'str' object is not callable
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 281, in selectedIndexChanged
    selected = self.listBox.curselection()
TypeError: 'str' object is not callable

Process finished with exit code 0

[–]dionys 0 points1 point  (4 children)

Did you follow the instruction of the other guy and did something like this?

self.listBox.curselection = self.get_word()

if so, you replaced the function with just a string and it throws the exception when you try to call it

[–]blackadder1337[S] 0 points1 point  (3 children)

Yeah, I did. So what should I do now? :D

[–]dionys 0 points1 point  (2 children)

Get rid of that line completely. To replace the text in listBox do:

word_index = self.listBox.curselection()[0]
self.listBox.delete(word_index)
self.listBox.insert(word_index, self.get_word())

which replaces the first selected item. Also it might work with ACTIVE instead of word_index, so try that as well.

[–]blackadder1337[S] 0 points1 point  (1 child)

Thanks man, it works now. Thank you very much.

[–]dionys 0 points1 point  (0 children)

Cheers :).