[Tutor] tk entry focus
jfouhy@paradise.net.nz
jfouhy at paradise.net.nz
Thu Jul 14 04:46:57 CEST 2005
Quoting Ron Weidner <xecronix at yahoo.com>:
> What's wrong with this code? Or more to the point,
> how do you set the focus to an Entry widget?
Look at what the error message is saying:
> self.cmd.focus()
> AttributeError: 'NoneType' object has no attribute
> 'focus'
Translation: self.cmd is a 'NoneType' object. There is only one NoneType
object: None. So, somehow, you have (effectively) done:
self.cmd = None
Let's see ...
> self.cmd = Entry( self.frame,
> textvariable=self.cmd_text ).grid( row = 1, column = 2 )
Aha. Here, you are creating an Entry widget, calling the grid() method on the
entry widget, and then assigning to self.cmd the return value _of the grid()
call_. This is extremely different from assigning to self.cmd the Entry widget
just created.
(can you guess what .grid() returns?)
You need to break your code up into two lines:
self.cmd = Entry(...)
self.cmd.grid(...)
Then give it a try :-)
--
John.
More information about the Tutor
mailing list