Unable to Import Tkinter

1,029 views
Skip to first unread message

306 kern

unread,
Sep 13, 2020, 9:32:02 PM9/13/20
to thonny

Hello, when I try to run a python code such as:

from Tkinter import *

I get the error:
Traceback (most recent call last):
  File "F:\myPython\frame7.py", line 2, in <module>
    from Tkinter import *
ModuleNotFoundError: No module named 'Tkinter'

Last, when I try to add the package Thonny can't find it.

Can anyone help me?
Thank you
Joe

André Roberge

unread,
Sep 14, 2020, 4:35:42 AM9/14/20
to thonny


On Sunday, 13 September 2020 22:32:02 UTC-3, 306 kern wrote:

Hello, when I try to run a python code such as:

from Tkinter import *

You are likely following a tutorial written for Python 2, an obsolete version of Python.

In Python 3, the module name is tkinter (lowercase t).

André Roberge

306 kern

unread,
Sep 14, 2020, 9:38:45 PM9/14/20
to thonny
Here is what I get when I try to import tkinter
thonny.jpg
What am I doing wrong?
Thank you,
Joe

306 kern

unread,
Sep 14, 2020, 9:40:58 PM9/14/20
to thonny
I tried the following:
from tkinter import *

def say_hi():
    print("hello ~ !")

root = Tk()

frame1 = Frame(root)
frame2 = Frame(root)
root.title("tkinter frame")

label= Label(frame1,text="Label",justify=LEFT)
label.pack(side=LEFT)

hi_there = Button(frame2,text="say hi~",command=say_hi)
hi_there.pack()

frame1.pack(padx=1,pady=1)
frame2.pack(padx=10,pady=10)

root.mainloop()

It worked, so maybe tkinter is already installed?

Thank you
Joe

André Roberge

unread,
Sep 15, 2020, 4:22:09 AM9/15/20
to 306 kern, thonny
On Mon, Sep 14, 2020 at 10:41 PM 306 kern <306...@gmail.com> wrote:
I tried the following:
from tkinter import *

SNIP 

It worked, so maybe tkinter is already installed?


Yes, it is. Python comes with a number of modules/packages in its "standard libraries". tkinter is one such package included on most platforms. Packages written by third-parties that are not included in the Python distribution need to be fetched from pypi (the standard Python Package repository), which is what you were attempting to do in the screenshot included in your previous email.

André Roberge

 
Thank you
Joe

On Monday, September 14, 2020 at 6:38:45 PM UTC-7 306 kern wrote:
Here is what I get when I try to import tkinter
thonny.jpg
What am I doing wrong?
Thank you,
Joe

On Monday, September 14, 2020 at 1:35:42 AM UTC-7 andre....@gmail.com wrote:


On Sunday, 13 September 2020 22:32:02 UTC-3, 306 kern wrote:

Hello, when I try to run a python code such as:

from Tkinter import *

You are likely following a tutorial written for Python 2, an obsolete version of Python.

In Python 3, the module name is tkinter (lowercase t).

André Roberge
 

I get the error:
Traceback (most recent call last):
  File "F:\myPython\frame7.py", line 2, in <module>
    from Tkinter import *
ModuleNotFoundError: No module named 'Tkinter'

Last, when I try to add the package Thonny can't find it.

Can anyone help me?
Thank you
Joe

--
You received this message because you are subscribed to a topic in the Google Groups "thonny" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/thonny/Y-eVgHAxR8k/unsubscribe.
To unsubscribe from this group and all its topics, send an email to thonny+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/thonny/717c4f55-9bdd-47f7-9d9a-f8887b8d1b46n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages