By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,766 Members | 1,393 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,766 IT Pros & Developers. It's quick & easy.

Tkinter focus_set use with grid

P: n/a
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(ro w=1, column=0)
btnCancel = Button(text="Cancel",
command=killer).grid(row=1, column=1)
master.mainloop()
return

Does anyone know where I went wrong?

Regards. . . .

__S Cook
Jul 20 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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(ro w=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.

Jul 20 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.