Gavin_XXd
Gavin_XXd

Reputation: 23

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

Upvotes: 0

Views: 767

Answers (1)

Himanshu Kawale
Himanshu Kawale

Reputation: 364

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()

Upvotes: 1

Related Questions