468,296 Members | 1,309 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,296 developers. It's quick & easy.

Tkinter focus_set use with grid

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
1 7113
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.

Similar topics

7 posts views Thread by Jane Austine | last post: by
2 posts views Thread by Svennglenn | last post: by
6 posts views Thread by Richard Lewis | last post: by
reply views Thread by Stewart Midwinter | last post: by
3 posts views Thread by Ant | last post: by
3 posts views Thread by dwelch91 | last post: by
5 posts views Thread by H J van Rooyen | last post: by
reply views Thread by NPC403 | last post: by
reply views Thread by Teichintx | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.