Tkinter focus_set use with grid

John McMonagle jmcmonagle at velseis.com.au
Wed Jul 19 23:10:25 EDT 2006


On Thu, 2006-07-20 at 02:53 +0000, Stan Cook wrote:
> A newbie to Tkinter here. . . . . .
> 
> I'm trying to set the focus on an Entry textbox with 
> focus_set.  I am using the grid manager.  I created the same 
> interface before using the  pack() method and the focus_set 
> worked, but now it says
> 
> "AttributeError: 'NoneType' object has no attribute 'focus_set'"
> 
> Below is the section of the code:
> 
> #	CREATES THE GUI FOR DCN INPUT
> def get_dcn():
> 	master = Tk()
> 	_dcn = StringVar()
> 	label1 = Label(text="Enter DCN:",width=10).grid(row=0)
> 	txtbox = Entry(relief=SUNKEN, width=20, takefocus=1, 
> textvariable=_dcn).grid(row=0, column=1)
> 	txtbox.focus_set()
> 	btnOK= 
> Button(text="OK",command=assign_dcn(_dcn)).grid(row=1, column=0)
> 	btnCancel = Button(text="Cancel", 
> command=killer).grid(row=1, column=1)
> 	master.mainloop()
> 	return
> 
> Does anyone know where I went wrong?


Yes.  You set txtbox to be the return result of Entry(...).grid(...)
which is None.

What you want to do is is set txtbox to a tkinter instance:


def get_dcn():
        master = Tk()
        _dcn = StringVar()
        label1 = Label(text="Enter DCN:",width=10)
	label1.grid(row=0)
        txtbox = Entry(relief=SUNKEN, 
                       width=20,
                       takefocus=1,
                       textvariable=_dcn)
	txtbox.grid(row=0, column=1)
        txtbox.focus_set()
        btnOK= Button(text="OK",command=assign_dcn(_dcn))
        btnOK.grid(row=1, column=0)
        btnCancel = Button(text="Cancel", command=killer)
        btnCancel.grid(row=1, column=1)
        master.mainloop()
        return

Regards,

John



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.




More information about the Python-list mailing list