I get the error _tkinter.TclError: bad window path name ".!button" and i'm not sure why I get the error _tkinter.TclError: bad window path name ".!button" and i'm not sure why tkinter tkinter

I get the error _tkinter.TclError: bad window path name ".!button" and i'm not sure why


The immediate problem is that you haven't given the buttons a parent. The tl;dr is that you just need to add Root (or some other appropriate parent window) to the constructors for Gen_Pbutton and Gen_EButton, as you do for all of your other widgets.


The following two lines have an important difference:

Gen_PButton = Button(Root, text = "PLAY", width = 10, font=('Arial', 15), command = self.Play_Game)Gen_PButton = Button(text = "PLAY", width = 10, font=('Arial', 15), command = self.Play_Game)

Both versions create a new name for a button widget (.!button in this case), and create a new tkinter.Button object associated with that name—but the first one also asks Root to create the actual widget named .!button, while the second one doesn't ask anyone to create the widget. So you end up with a Button object that's attached to a non-existent widget, and whenever you try to use that Button object, you get an error like this:

_tkinter.TclError: bad window path name ".!button"

The usual reason for an error like this is that you've destroyed the underlying button widget but keep trying to use the Button. But in this case, you never created the widget in the first place, which obviously leads to the same problem.


To understand exactly what's going on under the covers, you have to understand how Tkinter works—the actual GUI widgets and windows are managed by code in a completely different language, Tcl/Tk, and tkinter is association Python objects with Tcl objects by name and proxying every one of your method calls to those Tcl objects.


You may wonder why tkinter lets you get away with this construction in the first place, instead of giving you a more comprehensible error, one line earlier, something like this:

_tkinter.TclError: trying to create ".!button" with null parent

Well, technically, it's perfectly legal. You might create that Tcl widget later through some lower-level method, or you might have already created that Tcl widget and now just want to wrap a tkinter controller around it. Both are very rare cases, but they're not nonsensical, so tkinter allows for them.

And, more to the point: would you really understand the "better" error message any more easily? Neither one makes sense when you're first learning tkinter, and both are things you can learn to understand and deal with.