Tkinter focus_set use with grid

S

Stan Cook

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?

Regards. . . .

__S Cook
 
J

John McMonagle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top