using import * with GUIs?

J

John Salerno

Hi all. Quick question (but aren't they all?) :)

Do you think it's a good idea to use the 'from <name> import *'
statement when using a GUI module? It seems on wxPython's site, they
recommend using import wx nowadays, but I wonder if that advice is
followed. Also, I'm still reading some Tkinter docs that seem to use
'from Tkinter import *' a lot.

I understand the danger of doing this, but is it safer in these cases,
given the more specific names that GUI frameworks tend to use
(sometimes!)? Or should you still qualify all your calls with the module?
 
A

akameswaran

John said:
Hi all. Quick question (but aren't they all?) :)

Do you think it's a good idea to use the 'from <name> import *'
statement when using a GUI module? It seems on wxPython's site, they
recommend using import wx nowadays, but I wonder if that advice is
followed. Also, I'm still reading some Tkinter docs that seem to use
'from Tkinter import *' a lot.

I understand the danger of doing this, but is it safer in these cases,
given the more specific names that GUI frameworks tend to use
(sometimes!)? Or should you still qualify all your calls with the module?

The python style guide takes no position on this.
Personally I prefer explicit to implicit, and typing wx. is not really
that much to type is it?
 
T

Terry Reedy

John Salerno said:
Hi all. Quick question (but aren't they all?) :)

Do you think it's a good idea to use the 'from <name> import *'
statement when using a GUI module? It seems on wxPython's site, they
recommend using import wx nowadays, but I wonder if that advice is
followed. Also, I'm still reading some Tkinter docs that seem to use
'from Tkinter import *' a lot.

I understand the danger of doing this, but is it safer in these cases,
given the more specific names that GUI frameworks tend to use
(sometimes!)? Or should you still qualify all your calls with the module?

If I were to use Tkinter, I would 'import Tkinter as tk'.
 
A

Alexandre Fayolle

Le 31-05-2006 said:
Hi all. Quick question (but aren't they all?) :)

Do you think it's a good idea to use the 'from <name> import *'
statement when using a GUI module? It seems on wxPython's site, they
recommend using import wx nowadays, but I wonder if that advice is
followed. Also, I'm still reading some Tkinter docs that seem to use
'from Tkinter import *' a lot.

I understand the danger of doing this, but is it safer in these cases,
given the more specific names that GUI frameworks tend to use
(sometimes!)? Or should you still qualify all your calls with the module?


Don't overlook the "import module as shortname" construct, which is a
real lifesaver for large modules when you'd rather avoid importing *

Common idiom when using Numeric/numarray/numpy is

import Numeric as N

Importing Tkinter as tk is imo worth it.
 
J

John Salerno

Terry said:
If I were to use Tkinter, I would 'import Tkinter as tk'.

Good idea!

I was kind of excited about Tkinter for a little while...seems very
easy, and it has an event delegation system that I understand! But then
I saw that for a toolbar you use a Frame? And for a status bar you use a
Label? Ick!

I guess if I'm going to learn a GUI, I might as well jump right into
wxPython from the beginning.
 
M

malv

John said:
Good idea!

I was kind of excited about Tkinter for a little while...seems very
easy, and it has an event delegation system that I understand! But then
I saw that for a toolbar you use a Frame? And for a status bar you use a
Label? Ick!

I guess if I'm going to learn a GUI, I might as well jump right into
wxPython from the beginning.
Better first look at Qt/PyQt before jumping right into wxPython.
You will at least know what you will be jumping into.
 
M

Mel Wilson

John said:
Hi all. Quick question (but aren't they all?) :)

Do you think it's a good idea to use the 'from <name> import *'
statement when using a GUI module? It seems on wxPython's site, they
recommend using import wx nowadays, but I wonder if that advice is
followed. Also, I'm still reading some Tkinter docs that seem to use
'from Tkinter import *' a lot.

I understand the danger of doing this, but is it safer in these cases,
given the more specific names that GUI frameworks tend to use
(sometimes!)? Or should you still qualify all your calls with the module?
More specific? I dunno, I have trouble thinking of that
huge multitude of names in wx as specific. Who knows what
in all that might collide with names you devise?

My formative experience came when I was looking at Python
Imaging Library Demo code. Somebody did a simple call to
open and got returned an entire Jpeg image object. I knew
that open was destined to take arguments other than simple
file paths, and return things other than simple files, but
it seemed awfully soon. Then I got suspicious, looked at
the top of the code, and saw "from Image import *"

So a word, too, to people writing demo programs. Writing
"from mycode import *" obscures which code is actually yours
in the code following. Kind of defeats the purpose.

Cheers, Mel.
 
P

Peter Decker

I guess if I'm going to learn a GUI, I might as well jump right into
wxPython from the beginning.

May I recommend that you take a look at the Dabo project? While they
have a full application framework for creating database applications,
you can easily just use the dabo.ui module, which wraps wxPython. This
eliminates most of the C++ cruft that wxPython inherited from
wxWidgets, and makes for a much more Pythonic experience.

I worked with wxPython for a couple of years, and looked at Dabo based
on a recommendation on the wxPython list. Since then, I haven't
written a single app using raw wxPython; I use the dabo.ui module for
all my GUI applications. It gives you all the advantages of wxPython,
but it just works better.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,296
Messages
2,571,535
Members
48,281
Latest member
DaneLxa72

Latest Threads

Top