[Tutor] Fun with Label and Entry--Why NoneType?

ALAN GAULD alan.gauld at btinternet.com
Wed Mar 18 15:59:03 CET 2009


> That change got the same result. Maybe this will make it all clearer.

> When the prompt appears, there is a small window showing on the 
> screen,
2x2", 

Yes, that's the root window that Python expects you to put your GUI into.
The master that you pas to your GUI wFrames.

It didn't show for me with the code I posted.

How are you running this? Are you launching it from Windows Explorer 
or from a command line or from an IDE? I was just double clicking on the
file in explorer...

> My guess is that dialog needs to be "connected" to that root window. 

I suspect the problem is that you are trying to run a dialog as an application. 
Dialogs are normally launched from another window. So normally that Tk 
window would come up with the main app form, menus etc. Then from 
there you would perform an action (button, menu etc) that would launch 
the Dialog.

So we are kind of twisting the way Tkinter expects to be uased here.
But putting withdraw into the body method worked for me last night.

> IDLE
forces a hang in the shell window, which requires effort to 
> recover. 

As I keep saying, don't use IDLE to run Tkinter apps. Despite the 
supposed fixes it is not a reliable mechanism. Use ODLE as an editor 
but run the app from Windows Explorer or a command line

BTW I just double checked and when I double click in Explorer on 
the python file I only get the dialog and Dos box (which of course 
would go away if I changeed the file extension to .pyw)


Alan G

OK Try this version: 

# Derived from Grayson 5_14.py 
from   Tkinter import * 
from   tkSimpleDialog import Dialog 

class DialogPrototype(Dialog): 

   def body(self, master): 
       self.title("Enter Site Data") 

       Label(master, text='Latitude:').grid(row=0, sticky=W) 
       self.lat=Entry(master, width=12) 
       self.lat.grid(row=0, column=1) 
              Label(master, text='Longitude:').grid(row=0, column=2) 
       self.long=Entry(master, width=12) 
       self.long.grid(row=0, column=3) 
       self.master.withdraw() 
              
   def apply(self): 
       print "apply" 
       print self.lat.get() 
       print self.long.get() 

print "setting" 
lat=1.0 
long=0.0 

root = Tk() 
DialogPrototype(root) 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090318/9a7dd095/attachment.htm>


More information about the Tutor mailing list