A "First Real Example" binds "button" to None

49 views
Skip to first unread message

woooee

unread,
Jan 22, 2012, 2:30:01 AM1/22/12
to Tk Documentation and Resources
The grid() manager returns None so the variable "button" contains
None, and "why is it None" pops up on forums from time to time (so
please don't teach bad habits)
from tkinter import *
from tkinter import ttk
root = Tk()
button = ttk.Button(root, text="Hello World").grid()
root.mainloop()

it should either be just
tk.Button(root, text="Hello World").grid()
with an explanation that we aren't accessing the button further, or

button=tk.Button(root, text="Hello World")
button.grid()

Mark Roseman

unread,
Jan 23, 2012, 11:18:07 AM1/23/12
to tkd...@googlegroups.com, woooee
Doh! Thanks for noticing this… I've fixed it up in the tutorial.
Mark
Reply all
Reply to author
Forward
0 new messages