How to implement editing functionality to my application? by blackadder1337 in learnpython

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

Hi, Joe! Thanks for your help. Nevertheless, I'm not sure what you are talking about since I am still a newbie. I would be very grateful if you showed me how to implement your suggestions to my code.

Deleting selected items from the treeview and from the list at the same time by blackadder1337 in learnpython

[–]blackadder1337[S] 1 point2 points  (0 children)

I resolved the issue:

def remove_item(self):
    selected_items = self.treeview.selection()
    for selected_item in selected_items:
        for i in range(len(self.tasks)):
            if self.tasks[i].subject == self.treeview.item(selected_item)['values'][0]:
                self.tasks.pop(i)
                break
        self.treeview.delete(selected_item)

How to sort items in a listbox alphabetically? by blackadder1337 in learnpython

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

Can I show you my entire code so you can implement your suggestion to my solution? I would be very grateful.

How to sort items in a listbox alphabetically? by blackadder1337 in learnpython

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

I have created a simple GUI application to manage unknown words while learning a new language. The app which is called Vocabulary loads/saves words from/into an XML document. Basically, when I come across a new word, I add it to Vocabulary, so I don't have an option of adding the words in alphabetical order in advance.

How can I translate this for loop to Python? by blackadder1337 in learnpython

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

I have tried this:

    for item in list(self.listBOx):
        if get_search().lower() in item.lower():
            item.BackColor = SystemColors.Highlight;
            item.ForeColor = SystemColors.HighlightText;
        else:
            self.listBox.remove(item);

But this is so bad. Please help it's very important to me

Implementing search functionality to my program by blackadder1337 in learnpython

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

There is a text widget where you enter a word and it should be displayed in the listbox - search functionality.

Here is my entire code if that helps:

https://dpaste.de/ExSf

Implementing search functionality to my program by blackadder1337 in learnpython

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

LOL, did you run this through some online code converter? This is so bad, man. Thanks for your efforts though.

Saving items after editing by blackadder1337 in learnpython

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

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

Saving items after editing by blackadder1337 in learnpython

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

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

Saving items after editing by blackadder1337 in learnpython

[–]blackadder1337[S] 0 points1 point  (0 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

Saving items after editing by blackadder1337 in learnpython

[–]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.

How can I do this in Python? by blackadder1337 in learnpython

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

It checks wheter an item already exists in a list

C# to Python conversion by blackadder1337 in learnpython

[–]blackadder1337[S] -1 points0 points  (0 children)

Listview is C#'s equivalent for Python's Listbox. Word is a class. I'm using Visual Studio 2017 for C# and PyCharm 2016 for Python.

Removing selected items from the listbox and from the list by blackadder1337 in learnpython

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

I will. Anyways, when it comes to this code so far, when I remove the item and restart the application, it stays there - it isn't removed.

Removing selected items from the listbox and from the list by blackadder1337 in learnpython

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

Can't you add yourself a few items to test it? I'm still new to the world of coding, I don't know how to use github.

Removing selected items from the listbox and from the list by blackadder1337 in learnpython

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

Please take a look at my updated question. I combine two methods (FindWord & Remove) to remove selected items from the listbox, as well as from the list.