Search code examples
pythonpython-3.xtkinterappjar

Why does my code crash after i close my tKinter/appJar GUI?


First question here.

I'm new to Python, trying to make a text-based game using appJar for a UI - problem is, recently my GUI crashes my code when I exit out of it. Whether I close the window or use an Exit button that stops the GUI, I get this error and it prevents me from running any code after closing the UI.

Error:


    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))

Here is my code:

from appJar import gui 
import classes

def startProgram():
    # Main window and settings  
    with gui() as app:
        app.setTitle("CARAVAN")
        app.setSize("1000x700")
        app.setResizable(canResize=False)
        app.setGuiPadding(20, 20)
        app.setBg("dimgray", override=True)
        app.setFg("black", override=True)
        app.setFont(size=16, family="Source Code Pro")
        def exitProgram():
            app.stop()
        with app.labelFrame("Main Window", row=0, column=0, colspan=2, rowspan=2, stretch="both", sticky="nesw"):
            app.addButton("Exit", exitProgram, row=1, column=1)
        with app.labelFrame("Status", row=0, column=2, colspan=1, rowspan=1, stretch="row", sticky="nesw"):
            app.setStretch("both")
            app.setSticky("new")
            app.addLabel("Status1", row=0, column=0, colspan=1, rowspan=1)
            app.addLabel("Status2", row=1, column=0, colspan=1, rowspan=1)
        with app.labelFrame("Inventory", row=1, column=2, colspan=1, rowspan=1, stretch="row", sticky="nesw"):
            app.setStretch("both")
            app.setSticky("new")
            app.addLabel("Inv1", row=0, column=0, colspan=1, rowspan=1)
            app.addLabel("Inv2", row=1, column=0, colspan=1, rowspan=1)
        with app.labelFrame("Time", row=2, column=2, colspan=1, rowspan=1, stretch="row", sticky="esw"):
            app.addLabel("progress", "test")
        app.setSticky("esw")
        app.setStretch("column")
        app.addLabelEntry(" ", row=2, colspan=1)
        app.setEntryDefault(" ", "Respond here...")
    app.go()

startProgram()


Solution

  • invalid command name "." is telling you that the root window has been destroyed. "." is the internal name for the root window.

    You didn't show enough code to pinpoint the problem, but the bottom line is you're executing some tkinter code after the root window has been destroyed.