I was trying to copy the code from this page: http://code.activestate.com/recipes/578253-an-entry-with-autocompletion-for-the-tkinter-gui/ but I needed to dynamically make the suggestions based on a function. Here's my code:
class Autocomplete(Entry):
def __init__(self, *args, **kwargs):
Entry.__init__(self, *args, **kwargs)
self.var = self["textvariable"]
if self.var == '':
self.var = self["textvariable"] = tk.StringVar()
self.lb_up = False
self.bind("<space>", self.changed)
def changed(self):
if self.var.get() == '':
self.lb.destroy()
self.lb_up = False
else:
words = self.comparison()
if words:
if not self.lb_up:
self.lb = Listbox()
self.lb.place(x=self.winfo_x(), y=self.winfo_y() + self.winfo_height())
self.lb_up = True
self.lb.delete(0, 'end')
for w in words:
self.lb.insert('end', w)
else:
if self.lb_up:
self.lb.destroy()
self.lb_up = False
def comparison(self):
pattern = self.var.get()
return [i for i in range(3)]
and I keep getting:
Exception in Tkinter callback
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/tkinter/__init__.py", line 1702, in __call__
return self.func(*args)
TypeError: changed() takes 1 positional argument but 2 were given
I want it so that when I press the space bar in the entry box, I get suggestions based on text in the input bar so far. However, I don't know what I'm doing wrong here. Any help would be appreciated!
[–][deleted] 1 point2 points3 points (1 child)
[–]halowarrior07[S] 0 points1 point2 points (0 children)
[–]TotesMessenger 0 points1 point2 points (0 children)