Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading