Search code examples
python-3.xtkintertcl

Need help on _tkinter.TclError: invalid command name "<!DOCTYPE"


My question refers to this video:

At time 3:46 she runs the code for root widget:

from tkinter import ttk

root = tk.Tk()

root.mainloop()

No problem there, I get the same too.

However, at time 5:37 when she runs the widget code to display the "Forest" theme I get this error message.

import tkinter as tk
from tkinter import ttk

root = tk.Tk()

style = ttk.Style(root)
root.tk.call("source", "forest-light.tcl")
root.tk.call("source", "forest-dark.tcl")
style.theme_use("forest-dark")


root.mainloop()
Traceback (most recent call last):
  File "address to filename", line 8, in <module>
    root.tk.call('source', 'forest-light.tcl')
_tkinter.TclError: invalid command name "<!DOCTYPE"

I have tried including an asterisk at the first import line as I thought it's a version issue. No change

I even tried re-downloading the tcl files from the referred to GitHub page as I thought the files might be the problem. No headway

I am a beginner using Python 3.12. Thanks in advance for your advice.


Solution

  • You're trying to source a file that is expected to be Tcl code, but instead, the first line of the file begins with <!DOCTYPE. That means it's not tcl code. Instead, it is an html or xml file. You probably downloaded forest-light.tcl and/or forest-dark.tcl incorrectly.