0

My only code which i written is causing errors. Any ideas? Here is my error:

C:\Python27\python.exe "C:/Users/USER/Desktop/Python/AB-Windows.py"
Traceback (most recent call last):
  File "C:/Users/USER/Desktop/Python/AB-Windows.py", line 1, in <module>
    from tkinter import *
ImportError: No module named tkinter

Here's the code:

from tkinter import *

root = Tk()
root.mainloop()
CodeManYote
  • 9
  • 1
  • 4

1 Answers1

2

In python 2, replace import tkinter with import Tkinter with a capital T

from Tkinter import *

root = Tk()

root.mainloop()
Reblochon Masque
  • 35,405
  • 10
  • 55
  • 80
  • I'm using pycharm to code i tried what you said but was then given this error: C:\Python27\python.exe "C:/Users/Robert/Desktop/Roberts' Python/AB-Windows.py" Traceback (most recent call last): File "C:/Users/Robert/Desktop/Roberts' Python/AB-Windows.py", line 1, in from Tkinter import * File "C:\Python27\lib\lib-tk\Tkinter.py", line 659 ^ IndentationError: expected an indented block – CodeManYote Oct 02 '17 at 15:08
  • 2
    @robavioH That's a different error probably related to copy and pasting code without regard for formatting. Remember that in Python, code indentation is significant and there is a difference between tabs and spaces. – trent Oct 02 '17 at 15:37
  • This is due to copy pasting in your ide from SO - I changed the formatting in my post, but you still will have to chack it after pasting. – Reblochon Masque Oct 02 '17 at 15:39
  • @trentcl the trackback error tells you exactly what the problem is. Bad Indentation at line 1. Its a really easy fix. – Mike - SMT Oct 02 '17 at 15:56
  • I've tried using many types of indentation but to no prevail. Do you think its because there is an error with pycharm its self? – CodeManYote Oct 02 '17 at 20:44
  • @robavioH Looking at the stack trace, it seems like you changed something in Tkinter.py file. (maybe tried to look at source code then pressed space accidentally?) Can you please check the indentation in Tkinter.py line 659. – Lafexlos Oct 03 '17 at 10:57