Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #61247 > unrolled thread
| Started by | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| First post | 2013-12-07 08:52 -0800 |
| Last post | 2013-12-08 00:57 -0800 |
| Articles | 13 — 6 participants |
Back to article view | Back to comp.lang.python
[newbie] struggling wth tkinter Jean Dubois <jeandubois314@gmail.com> - 2013-12-07 08:52 -0800
Re: [newbie] struggling wth tkinter Dave Angel <davea@davea.name> - 2013-12-07 13:12 -0500
Re: [newbie] struggling wth tkinter Jean Dubois <jeandubois314@gmail.com> - 2013-12-07 23:40 -0800
Re: [newbie] struggling wth tkinter Chris Angelico <rosuav@gmail.com> - 2013-12-08 18:49 +1100
Re: [newbie] struggling wth tkinter Jean Dubois <jeandubois314@gmail.com> - 2013-12-08 01:15 -0800
Re: [newbie] struggling wth tkinter Cousin Stanley <cousinstanley@gmail.com> - 2013-12-07 11:23 -0700
Re: [newbie] struggling wth tkinter Jean Dubois <jeandubois314@gmail.com> - 2013-12-07 23:45 -0800
Re: [newbie] struggling wth tkinter Dave Angel <davea@davea.name> - 2013-12-08 09:16 -0500
Re: [newbie] struggling wth tkinter Jean Dubois <jeandubois314@gmail.com> - 2013-12-08 07:53 -0800
Re: [newbie] struggling wth tkinter Cousin Stanley <cousinstanley@gmail.com> - 2013-12-08 07:16 -0700
Re: [newbie] struggling wth tkinter Terry Reedy <tjreedy@udel.edu> - 2013-12-07 16:11 -0500
Re: [newbie] struggling wth tkinter Christian Gollwitzer <auriocus@gmx.de> - 2013-12-08 09:10 +0100
Re: [newbie] struggling wth tkinter Jean Dubois <jeandubois314@gmail.com> - 2013-12-08 00:57 -0800
| From | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| Date | 2013-12-07 08:52 -0800 |
| Subject | [newbie] struggling wth tkinter |
| Message-ID | <40121057-3c98-4f50-84b3-fd320fe2cedc@googlegroups.com> |
I'm trying to go through a tutorial on tkinter which has the code below as an example. The only thing I see when running it is a little popup with "Click mouse here to quit" which works as expected but always shows the following error-message.
However the "main" window which should let you enter the numbers is not shown.
This is the quit error message:
Traceback (most recent call last):
File "./feet2meters.py", line 3, in <module>
from tkinter import ttk
ImportError: cannot import name ttk
This is the code:
#!/usr/bin/env python
from tkinter import *
from tkinter import ttk
def calculate(*args):
try:
value = float(feet.get())
meters.set((0.3048 * value * 10000.0 + 0.5)/10000.0)
except ValueError:
pass
root = Tk()
root.title("Feet to Meters")
mainframe = ttk.Frame(root, padding="3 3 12 12")
mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
mainframe.columnconfigure(0, weight=1)
mainframe.rowconfigure(0, weight=1)
feet = StringVar()
meters = StringVar()
feet_entry = ttk.Entry(mainframe, width=7, textvariable=feet)
feet_entry.grid(column=2, row=1, sticky=(W, E))
ttk.Label(mainframe, textvariable=meters).grid(column=2, row=2, sticky=(W, E))
ttk.Button(mainframe, text="Calculate", command=calculate).grid(column=3, row=3, sticky=W)
ttk.Label(mainframe, text="feet").grid(column=3, row=1, sticky=W)
ttk.Label(mainframe, text="is equivalent to").grid(column=1, row=2, sticky=E)
ttk.Label(mainframe, text="meters").grid(column=3, row=2, sticky=W)
for child in mainframe.winfo_children(): child.grid_configure(padx=5, pady=5)
feet_entry.focus()
root.bind('<Return>', calculate)
root.mainloop()
thanks in advance
jean
[toc] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-12-07 13:12 -0500 |
| Message-ID | <mailman.3706.1386439915.18130.python-list@python.org> |
| In reply to | #61247 |
On Sat, 7 Dec 2013 08:52:08 -0800 (PST), Jean Dubois <jeandubois314@gmail.com> wrote: > I'm trying to go through a tutorial on tkinter which has the code below as an example. The only thing I see when running it is a little popup with "Click mouse here to quit" which works as expected but always shows the following error-message. > However the "main" window which should let you enter the numbers is not shown. > This is the quit error message: > Traceback (most recent call last): > File "./feet2meters.py", line 3, in <module> > from tkinter import ttk > ImportError: cannot import name ttk > This is the code: > #!/usr/bin/env python > from tkinter import * > from tkinter import ttk Thanks for supplying the complete traceback. But you should also tell the python version and what OS. I'll guess python 3.3 on Linux. Finally, what version tk are you running? These widgets were introduced in tk 8.5 Since it failed on the second import, none of the rest of the code matters. However, since you're not running it from a terminal window, it's conceivable that your ide is affecting the result. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| Date | 2013-12-07 23:40 -0800 |
| Message-ID | <c4184cdc-8caf-4c6e-996a-2840a814b502@googlegroups.com> |
| In reply to | #61253 |
Op zaterdag 7 december 2013 19:12:50 UTC+1 schreef Dave Angel:
> On Sat, 7 Dec 2013 08:52:08 -0800 (PST), Jean Dubois
>
> <jeandubois314@gmail.com> wrote:
>
> > I'm trying to go through a tutorial on tkinter which has the code
>
> below as an example. The only thing I see when running it is a little
>
> popup with "Click mouse here to quit" which works as expected but
>
> always shows the following error-message.
>
> > However the "main" window which should let you enter the numbers is
>
> not shown.
>
> > This is the quit error message:
>
> > Traceback (most recent call last):
>
> > File "./feet2meters.py", line 3, in <module>
>
> > from tkinter import ttk
>
> > ImportError: cannot import name ttk
>
>
>
> > This is the code:
>
> > #!/usr/bin/env python
>
> > from tkinter import *
>
> > from tkinter import ttk
>
>
>
> Thanks for supplying the complete traceback. But you should also
>
> tell the python version and what OS. I'll guess python 3.3 on Linux.
>
>
>
>
>
> Finally, what version tk are you running? These widgets were
>
> introduced in tk 8.5
>
>
>
> Since it failed on the second import, none of the rest of the code
>
> matters. However, since you're not running it from a terminal window,
>
> it's conceivable that your ide is affecting the result.
>
>
>
> --
>
> DaveA
I have two pythons installed on my system:
Python 2.7.3 and Python 3.2.3
When using python2 I get the errors mentioned above
When using python3 (I removed the shebang and started as python3 feettometers.py) then I get these errors:
coolens@antec2:~$ python3 feet2meters.py
Traceback (most recent call last):
File "feet2meters.py", line 1, in <module>
from tkinter import *
File "/home/coolens/tkinter.py", line 2, in <module>
import Tkinter as tk
ImportError: No module named Tkinter
I tried to fix this by installing
apt-get install python3-tk (python3-tk_3.2.3-1_amd64.deb)
but the error remains
What should I do now?
thanks in advance
jean
[toc] | [prev] | [next] | [standalone]
| From | Chris Angelico <rosuav@gmail.com> |
|---|---|
| Date | 2013-12-08 18:49 +1100 |
| Message-ID | <mailman.3719.1386488971.18130.python-list@python.org> |
| In reply to | #61275 |
On Sun, Dec 8, 2013 at 6:40 PM, Jean Dubois <jeandubois314@gmail.com> wrote:
> coolens@antec2:~$ python3 feet2meters.py
> ImportError: No module named Tkinter
In Python 3, the module's named tkinter instead of Tkinter. You should
be able to do the exact same import but with the lower-case name, or
if you need to support both:
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
ChrisA
[toc] | [prev] | [next] | [standalone]
| From | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| Date | 2013-12-08 01:15 -0800 |
| Message-ID | <306a33b1-d9f9-433b-91fa-b89b99e774eb@googlegroups.com> |
| In reply to | #61277 |
Op zondag 8 december 2013 08:49:22 UTC+1 schreef Chris Angelico:
> On Sun, Dec 8, 2013 at 6:40 PM, Jean Dubois <jeandubois314@gmail.com> wrote:
>
> > coolens@antec2:~$ python3 feet2meters.py
>
> > ImportError: No module named Tkinter
>
>
>
> In Python 3, the module's named tkinter instead of Tkinter. You should
>
> be able to do the exact same import but with the lower-case name, or
>
> if you need to support both:
>
>
>
> try:
>
> import tkinter as tk
>
> except ImportError:
>
> import Tkinter as tk
>
This seems a very nice approach, but can you tell me how I should change the import-section as a whole; I tried it like here below (but that's certainly not the right way):
try:
import tkinter as tk
except ImportError:
import Tkinter as tk
from tk import *
import ttk
thanks in advance
jean
[toc] | [prev] | [next] | [standalone]
| From | Cousin Stanley <cousinstanley@gmail.com> |
|---|---|
| Date | 2013-12-07 11:23 -0700 |
| Message-ID | <l7vp35$dnc$1@dont-email.me> |
| In reply to | #61247 |
> ....
> The only thing I see when running it is a little popup
> with "Click mouse here to quit" which works as expected
> but always shows the following error-message.
This seems to be left over from an earlier post
where you were binding a mouse event to a tk label
Did you create a new file ?
> However the "main" window which should let you enter the
> numbers is not shown.
>
> This is the quit error message:
> Traceback (most recent call last):
> File "./feet2meters.py", line 3, in <module>
> from tkinter import ttk
> ImportError: cannot import name ttk
>
> This is the code:
> ....
If I copy/paste your code as posted
into a new file named ftom.py
and change the she-bang line
as follows ....
#!/usr/bin/env python3
Then from the command line ....
python3 ftom.py
Your code runs as expected
using python 3.2.3 ....
--
Stanley C. Kitching
Human Being
Phoenix, Arizona
[toc] | [prev] | [next] | [standalone]
| From | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| Date | 2013-12-07 23:45 -0800 |
| Message-ID | <3d9e313c-958f-4532-b968-0aee7f849246@googlegroups.com> |
| In reply to | #61254 |
Op zaterdag 7 december 2013 19:23:30 UTC+1 schreef Cousin Stanley:
> > ....
>
> > The only thing I see when running it is a little popup
>
> > with "Click mouse here to quit" which works as expected
>
> > but always shows the following error-message.
>
>
>
> This seems to be left over from an earlier post
>
> where you were binding a mouse event to a tk label
>
>
>
> Did you create a new file ?
>
>
>
>
>
> > However the "main" window which should let you enter the
>
> > numbers is not shown.
>
> >
>
> > This is the quit error message:
>
> > Traceback (most recent call last):
>
> > File "./feet2meters.py", line 3, in <module>
>
> > from tkinter import ttk
>
> > ImportError: cannot import name ttk
>
> >
>
> > This is the code:
>
> > ....
>
>
>
> If I copy/paste your code as posted
>
> into a new file named ftom.py
>
> and change the she-bang line
>
> as follows ....
>
>
>
> #!/usr/bin/env python3
>
>
>
> Then from the command line ....
>
>
>
> python3 ftom.py
>
>
>
> Your code runs as expected
>
> using python 3.2.3 ....
I tried you suggestion above:
This is what I get:
Traceback (most recent call last):
File "./feet2meters.py", line 2, in <module>
from tkinter import *
File "/home/jean/tkinter.py", line 2, in <module>
import Tkinter as tk
ImportError: No module named Tkinter
and this is my python3-version:
Python 3.2.3 (default, Sep 25 2013, 18:22:43)
[GCC 4.6.3] on linux2
any idea what is going wrong?
thanks in advance
jean
[toc] | [prev] | [next] | [standalone]
| From | Dave Angel <davea@davea.name> |
|---|---|
| Date | 2013-12-08 09:16 -0500 |
| Message-ID | <mailman.3730.1386512136.18130.python-list@python.org> |
| In reply to | #61276 |
On Sat, 7 Dec 2013 23:45:06 -0800 (PST), Jean Dubois <jeandubois314@gmail.com> wrote: > This is what I get: > Traceback (most recent call last): > File "./feet2meters.py", line 2, in <module> > from tkinter import * > File "/home/jean/tkinter.py", line 2, in <module> > import Tkinter as tk > ImportError: No module named Tkinter Regardless of your other fixes, you should rename the bogus file: /home/jean/tkinter.py You very seldom want to have files that can shadow system modules. -- DaveA
[toc] | [prev] | [next] | [standalone]
| From | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| Date | 2013-12-08 07:53 -0800 |
| Message-ID | <f471f1fe-156d-4e56-9684-eabb07fb3dee@googlegroups.com> |
| In reply to | #61293 |
Op zondag 8 december 2013 15:16:25 UTC+1 schreef Dave Angel: > On Sat, 7 Dec 2013 23:45:06 -0800 (PST), Jean Dubois > > <jeandubois314@gmail.com> wrote: > > > This is what I get: > > > Traceback (most recent call last): > > > File "./feet2meters.py", line 2, in <module> > > > from tkinter import * > > > File "/home/jean/tkinter.py", line 2, in <module> > > > import Tkinter as tk > > > ImportError: No module named Tkinter > > > > Regardless of your other fixes, you should rename the bogus file: > > > > /home/jean/tkinter.py > > > > You very seldom want to have files that can shadow system modules. > > > > -- > > DaveA Thank you Dave, this made it work under python3 too. I also had to remove tkinter.pyc kind regards, jean
[toc] | [prev] | [next] | [standalone]
| From | Cousin Stanley <cousinstanley@gmail.com> |
|---|---|
| Date | 2013-12-08 07:16 -0700 |
| Message-ID | <l81v0e$62d$1@dont-email.me> |
| In reply to | #61276 |
> ....
> This is what I get:
>
> Traceback (most recent call last):
> File "./feet2meters.py", line 2, in <module>
> from tkinter import *
> File "/home/jean/tkinter.py", line 2, in <module>
> import Tkinter as tk
> ImportError: No module named Tkinter
> ....
From your original post I only changed the she-bang line
from python to python3 ....
#!/usr/bin/env python3
and the import lines remained
as you originally posted
which are appropriate for python3 ....
from tkinter import *
from tkinter import ttk
The traceback above shows an import statement
that is different from the one you originally posted
which would be ok in python2 but not python3 ....
import Tkinter as tk
--
Stanley C. Kitching
Human Being
Phoenix, Arizona
[toc] | [prev] | [next] | [standalone]
| From | Terry Reedy <tjreedy@udel.edu> |
|---|---|
| Date | 2013-12-07 16:11 -0500 |
| Message-ID | <mailman.3709.1386450711.18130.python-list@python.org> |
| In reply to | #61247 |
On 12/7/2013 1:12 PM, Dave Angel wrote: > On Sat, 7 Dec 2013 08:52:08 -0800 (PST), Jean Dubois > <jeandubois314@gmail.com> wrote: >> I'm trying to go through a tutorial on tkinter which has the code > below as an example. The only thing I see when running it is a little > popup with "Click mouse here to quit" which works as expected but always > shows the following error-message. >> However the "main" window which should let you enter the numbers is > not shown. >> This is the quit error message: >> Traceback (most recent call last): >> File "./feet2meters.py", line 3, in <module> >> from tkinter import ttk >> ImportError: cannot import name ttk That is supposed to work. >> This is the code: >> #!/usr/bin/env python >> from tkinter import * >> from tkinter import ttk > > Thanks for supplying the complete traceback. But you should also tell > the python version and what OS. I'll guess python 3.3 on Linux. > > Finally, what version tk are you running? These widgets were > introduced in tk 8.5 In 8.4, they were in the Tile extension. I do not know if that will work. Better, probably, to upgrade. > > Since it failed on the second import, none of the rest of the code > matters. However, since you're not running it from a terminal window, > it's conceivable that your ide is affecting the result. Until you are able to import ttk, I believe you could remove the import and all 'ttk.' appearances, as I do not see anything ttk-specific. -- Terry Jan Reedy
[toc] | [prev] | [next] | [standalone]
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Date | 2013-12-08 09:10 +0100 |
| Message-ID | <l819hj$qhn$2@dont-email.me> |
| In reply to | #61247 |
Am 07.12.13 17:52, schrieb Jean Dubois: > I'm trying to go through a tutorial on tkinter which has the code below as an example. The only thing I see when running it is a little popup with "Click mouse here to quit" which works as expected but always shows the following error-message. > However the "main" window which should let you enter the numbers is not shown. > > This is the quit error message: > Traceback (most recent call last): > File "./feet2meters.py", line 3, in <module> > from tkinter import ttk > ImportError: cannot import name ttk > > This is the code: > #!/usr/bin/env python > from tkinter import * > from tkinter import ttk With my python2, it works to replace the import by from Tkinter import * import ttk Christian
[toc] | [prev] | [next] | [standalone]
| From | Jean Dubois <jeandubois314@gmail.com> |
|---|---|
| Date | 2013-12-08 00:57 -0800 |
| Message-ID | <74c0caeb-0543-4819-a291-80e679344d6e@googlegroups.com> |
| In reply to | #61278 |
Op zondag 8 december 2013 09:10:28 UTC+1 schreef Christian Gollwitzer: > Am 07.12.13 17:52, schrieb Jean Dubois: > > > I'm trying to go through a tutorial on tkinter which has the code below as an example. The only thing I see when running it is a little popup with "Click mouse here to quit" which works as expected but always shows the following error-message. > > > However the "main" window which should let you enter the numbers is not shown. > > > > > > This is the quit error message: > > > Traceback (most recent call last): > > > File "./feet2meters.py", line 3, in <module> > > > from tkinter import ttk > > > ImportError: cannot import name ttk > > > > > > This is the code: > > > #!/usr/bin/env python > > > > > from tkinter import * > > > from tkinter import ttk > > > > With my python2, it works to replace the import by > > > > from Tkinter import * > > import ttk > > > > Christian Thank you very much Christian, this solves the problem kind regards, jean
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web