Home > Back-end >  How to fix this? NameError: name 'root' is not defined
How to fix this? NameError: name 'root' is not defined

Time:06-16

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

CodePudding user response:

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