Python Forum
python works on python 2 but not 3 - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: GUI (https://python-forum.io/forum-10.html)
+--- Thread: python works on python 2 but not 3 (/thread-23688.html)



python works on python 2 but not 3 - pythonbegginer - Jan-12-2020

hi, i am trying to open a blank window with tkinter. I am using this code for python 3
import tkinter
root = tkinter.Tk() 
print ("test")
root.mainloop()
I run it using python3 tkinter.py

this is the code for python2
import Tkinter
root = Tkinter.Tk()

print ("test")
root.mainloop()
I run it using python tkinter2.py

When i run tkinter.py it gives me the error
Error:
AttributeError: module 'tkinter' has no attribute 'Tk'
and when i run tkinter2.py it works fine.


RE: python works on python 2 but not 3 - balenaucigasa - Jan-12-2020

add in line one if use python 3
#!/usr/bin/python3
or add
#!/usr/bin/python
for python 2