0

I am just learning MVC and im using Tkinter to do so, but while i am trying to configure a button from a class within a class i keep getting this error

Traceback (most recent call last):
  File "Controller.py", line 22, in <module>
    controller = Controller(root)
  File "Controller.py", line 10, in __init__
    self.view.addWidgets.btn.config(command=self.addShow)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1205, in configure
    return self._configure('configure', cnf, kw)
  File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1196, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".35986680.35987112.35991848"

If you cant determine the problem from the error i can post my code, but they are in two separate files, although the files are only 40 lines long.

Details:

Button is in Frame class
Frame class is in View class
View class is in Controller class
function being called by Button command is in Controller class
    error happens when i configure button from Controller class
    self.view.addWidgets.btn.config(command=self.addShow)

Edit

I striped the code.

Controller.py

from View import *
from Model import *
from Tkinter import *

class Controller:
    def __init__(self,root):
        self.model = Model()
        self.view = View(root)

        self.view.addWidgets.btn.config(command=self.addShow)

    def addShow(self):
        print 'Working'


root=Tk()
root.withdraw()
controller = Controller(root)
root.mainloop()

View.py

from Tkinter import *
from MultiListbox import *
from AddFrame import *  

class View(Toplevel):
    def __init__(self, master):
        Toplevel.__init__(self, master)
        self.title('Show Preserver')

        self.protocol(self.protocol('WM_DELETE_WINDOW', master.destroy))#When i delete this i dont get the error but it still dosent work

        self.addFrame=Frame(self,bg='black')
        self.addWidgets=AddFrame(self.addFrame)

        self.addFrame.grid(row=0)

        self.mainloop()

AddFrame.py

#Add Frame
from Tkinter import *

class AddFrame(Frame):

    def __init__(self,master):

        self.frame = Frame(master,bg='black')
        self.frame.grid(row=0,column=0,sticky=W+E)

        self.btn = Button(self.frame,text='Add',bg='black',fg='yellow',activebackground='yellow',activeforeground='black', width=2,command=None)     
        self.btn.grid(row=0,column=6,sticky=E)
Brandon Nadeau
  • 3,568
  • 13
  • 42
  • 65

1 Answers1

1

The error invalid command name ".35986680.35987112.35991848" comes from the underlying Tcl interpreter which powers Tkinter. .35986680.35987112.35991848 is the low-level identifier for the widget, and it also represents a proxy command which is used to interact with that widget. Since Tcl is saying "invalid command name", that almost always means that the low level widget has been destroyed since the command goes away when the widget is destroyed.

Looking at your code, it appears that .35986680.35987112.35991848 represents self.view.AddWidgets.btn. Are you certain that widget still exists at the time you try to configure it?

[time passes, and now the question has some code...]

You are calling mainloop twice, which is not how Tkinter is designed to be used. You need to remove one of those.

Bryan Oakley
  • 370,779
  • 53
  • 539
  • 685