I am trying to add new options to a Tkinter OptionMenu
. I'm also watching for changes in the variables which the menu alters.
self.chosen_table = tk.StringVar(frame)
self.chosen_table.set("Please select a table...")
self.table_menu = tk.OptionMenu(frame, self.chosen_table,
"Please select a table...",
*self.tables.keys())
self.chosen_table.trace("w", self.update_current_table)
self.update_current_table
is just an assignment, nothing fancy. I am trying to add options to the menu dynamically like so:
new_comm = tk._setit(self.chosen_table, table_name)
self.table_menu['menu'].add_command(label=table_name, command=new_comm)
This adds the new option to the menu just fine, but when I try to select the new option I get the following error:
Exception in Tkinter callback
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 1549, in __call__
return self.func(*args)
File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 3285, in __call__
self.__var.set(self.__value)
File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 260, in set
return self._tk.globalsetvar(self._name, value)
_tkinter.TclError: can't set "PY_VAR0":
Traceback (most recent call last):
File "/usr/local/Cellar/python3/3.5.0/Frameworks/Python.framework/Versions/3.5/lib/python3.5/tkinter/__init__.py", line 1549, in __call__
return self.func(*args)
TypeError: update_current_table() takes 1 positional argument but 4 were given
I don't know what arguments I'm giving to update_current_table
, which only takes self
as an argument, and I don't know how to check without altering a sizable chunk of Tkinter code. I'm certain that the problem is due to my adding an option dynamically, as I had no such errors before I did that.