OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

Tkinter bind command to Listbox delay

  • Thread starter Thread starter ariel
  • Start date Start date
A

ariel

Guest
recently I've made a global function for my program (instead of many locals) that when pressing on a Listbox item -> it will put its text inside the entry widget, kind of "autocomplete" method (like in the image).. the problem that I'm facing is that now when I made the local "autocomplete" functions into one global one there's delay by one iteration between the Listbox item that you're clicking to the text that it will output to you in the Entry widget.

New fucntion:

Code:
   @staticmethod
    def fill_by_click(ui_element, event, listbox):
        ui_element.delete(0, END)
        ui_element.insert(END, listbox.get(ACTIVE))


    def somefunction(self):
       self.functions_list.bind('<<ListboxSelect>>', lambda e: self.fill_by_click(self.find_function, e, self.functions_list))

older ones:

Code:
      def somefunction(self):
         def insert_entry(term):
            self.find_text_entry.delete(0, END)
            self.find_text_entry.insert(END, popular_terms.get(ACTIVE))
          popular_terms.bind('<<ListboxSelect>>', insert_entry)

it's probably a combination of using lambda and giving widget as parameters but I don't know how to resolve it. I've tried to make some solution, but I've ended only with some dirty and chunky ones.
<p>recently I've made a global function for my program (instead of many locals) that when pressing on a Listbox item -> it will put its text inside the entry widget, kind of "autocomplete" method <a href="https://i.sstatic.net/pCaoEvfg.png" rel="nofollow noreferrer">(like in the image).</a>.
the problem that I'm facing is that now when I made the local "autocomplete" functions into one global one there's delay by one iteration between the Listbox item that you're clicking to the text that it will output to you in the Entry widget.</p>
<p>New fucntion:</p>
<pre class="lang-py prettyprint-override"><code> @staticmethod
def fill_by_click(ui_element, event, listbox):
ui_element.delete(0, END)
ui_element.insert(END, listbox.get(ACTIVE))


def somefunction(self):
self.functions_list.bind('<<ListboxSelect>>', lambda e: self.fill_by_click(self.find_function, e, self.functions_list))
</code></pre>
<p>older ones:</p>
<pre><code> def somefunction(self):
def insert_entry(term):
self.find_text_entry.delete(0, END)
self.find_text_entry.insert(END, popular_terms.get(ACTIVE))
popular_terms.bind('<<ListboxSelect>>', insert_entry)

</code></pre>
<p>it's probably a combination of using lambda and giving widget as parameters but I don't know how to resolve it.
I've tried to make some solution, but I've ended only with some dirty and chunky ones.</p>
 

Online statistics

Members online
0
Guests online
4
Total visitors
4
Top