This is for a school project - we have to make a quiz using python that has login credentials, file i/o including questions loaded from a file, storing statistics in a file etc. During runtime, I get this error:

Exception in Tkinter callback
  Traceback (most recent call last):
  File "C:\Program Files (x86)\Python\lib\tkinter\__init__.py", line 1699, in __call__
    return self.func(*args)
  File "E:\Python\Coursework\Coursework Quiz.py", line 259, in click_d
    do_quiz(contents)
  File "E:\Python\Coursework\Coursework Quiz.py", line 272, in do_quiz
    question.config(text=(line.split("|")[0]))
  File "C:\Program Files (x86)\Python\lib\tkinter\__init__.py", line 1479, in configure
    return self._configure('configure', cnf, kw)
  File "C:\Program Files (x86)\Python\lib\tkinter\__init__.py", line 1470, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: invalid command name ".!label13"

The code in question is:

def physics():
    global level, contents, subject
    subject = "Physics"
    with open("Physics Questions.txt", "r") as f:
        contents = f.read().splitlines()
        if level == "easy":
            contents = contents[:5]
        elif level == "medium":
            contents = contents[5:10]
        elif level == "hard":
            contents = contents[10:]
        do_quiz(contents)

def do_quiz(questions):
    global line, current, level
    try:
        line = questions[current]
    except IndexError:
        final(level, subject)
    subjectLabel.grid_forget()
    physicsButton.grid_forget()
    mathsButton.grid_forget()
    genknowledgeButton.grid_forget()
    question.config(text=(line.split("|")[0]))

def click_a():
    global line, score, contents, current
    if line.split("|")[1] == "a":
        score += 1
    current += 1
    do_quiz(contents)

where line is a line from a file that contains questions

Edit: Included where the function is being called

2 upvote
  flag
The code above wouldn't produce the error as is, please provide a Minimal, Complete, and Verifiable example. – Nae
upvote
  flag
What that error tells is that you're trying to pass an instance of tkinter.Label as if it is a Tcl command. – Nae
upvote
  flag
I'd guess replace line.split(... with line['text'].split(.... – Nae

0 Answers 11

Not the answer you're looking for? Browse other questions tagged or ask your own question.