How to fix this? NameError: name 'root' is not defined

So, I want to create an icon. I wrote that code and i have this problem. Is there anything missing from the code below?

from tkinter import *

root.Tk()
root.title("Hello World")
root.iconbitmap("C:/Users/Ciss/Desktop/Mine/Python/www.ico")

root.mainloop()

Result:

Traceback (most recent call last):
  File "C:\Users\Ciss\Desktop\Mine\Python\py.py", line 9, in <module>
    root.mainloop()
NameError: name 'root' is not defined

>Solution :

As the error says, you didn’t define root

what is root in root.Tk()?

You can do something like this,

from tkinter import *

root = Tk()
root.title("Hello World")
root.iconbitmap("C:/Users/Ciss/Desktop/Mine/Python/www.ico")

root.mainloop()

Leave a Reply