title: Python Tkinter Tk is not defined
body: <p>I need help with making this simple Tkinter program work on Ubuntu 16.04.1 with Python 3.5.2.</p>
  
  <p>Here's the code:</p>
  
  <pre><code>from tkinter import *
  
  root = Tk()
  mylabel = Label(root, text="Test")
  mylabel.pack()
  
  root.mainloop()
  </code></pre>
  
  <p>The code as-is gives me this error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "tkinter.py", line 8, in &lt;module&gt;
      from tkinter import *
    File "/home/dylan/Documents/proj/python/tkinter.py", line 10, in &lt;module&gt;
      root = Tk()
  NameError: name 'Tk' is not defined
  </code></pre>
  
  <p>I noticed browsing other questions that there are a few popular things that
  can go wrong when making a Tkinter program.</p>
  
  <ol>
  <li><em>Tkinter is not installed.</em>
  I installed both the <code>python-tk</code> and <code>python3-tk</code> packages before updating my packages, saving my file, and running my program with <code>python3 tkinter.py</code>.</li>
  </ol>
  
  <p><strong>Note:</strong> renaming my file to something other than <code>tkinter.py</code> results in a weird error:</p>
  
  <pre><code>Traceback (most recent call last):
    File "mytkinter.py", line 8, in &lt;module&gt;
      from tkinter import *
  ImportError: bad magic number in 'tkinter': b'\x03\xf3\r\n'
  </code></pre>
  
  <ol start="2">
  <li><p><em>The import name is wrong.</em>
  Using <code>tkinter</code> with a lowercase gives me the <code>Tk() not defined</code> error, indicating the import name is correct, but the name Tk is not.
  Using it with an uppercase T gives me a <code>no module named Tkinter</code> error.
  Using <code>tkinter.Tk()</code> results in a <code>tkinter is not defined</code> error.
  <a href="https://stackoverflow.com/questions/26702119/installing-tkinter-on-ubuntu-14-04">Installing tkinter on ubuntu 14.04</a></p></li>
  <li><p><em>The case in the code, or the instantiation of <code>Tk()</code>, or similar names, is wrong.</em>
  Typing</p>
  
  <ul>
  <li><code>root = tk()</code></li>
  <li><code>root = Tk()</code></li>
  <li><code>root = tkinter()</code></li>
  <li><code>root = Tkinter()</code></li>
  <li><code>root = tkinter.tk()</code></li>
  <li><code>root = tkinter.Tk()</code></li>
  <li><code>root = Tkinter.tk()</code></li>
  <li><code>root = Tkinter.Tk()</code></li>
  <li><code>root = tk.Tk()</code></li>
  <li><code>root = Tk.Tk()</code></li>
  </ul></li>
  </ol>
  
  <p>all result in NameErrors.
  <a href="https://stackoverflow.com/questions/8275818/programming-in-python-getting-name-tk-is-not-defined-only-at-command-prompt">Programming in Python: Getting &quot;name &#39;Tk&#39; is not defined&quot; only at Command Prompt, works in IDLE</a></p>
  
  <p>Another thing to note: the command <code>python3 -m idlelib.idle</code>, as seen in the question below, results in a <code>Tk not defined</code> error as well.
  <a href="https://stackoverflow.com/questions/26573776/tk-is-not-defined">&#39;Tk&#39; is not defined</a></p>
  
  <p>What could be the problem here?</p>