Reputation: 19
I am using Python 3.5, Tkinter 8.6 on a Windows 7 platform. For the simple code below, I keep getting the following error message...
button2.bind("<Button-1>",PrintAddress)
AttributeError: 'NoneType' object has no attribute 'bind'
CODE
from tkinter import *
root = Tk()
root.geometry('200x200')
def PrintName():
print("My name is ..........")
def PrintAddress(event):
print("W223 N2257...........")
button1 = Button(root,text = 'Print Name', command=PrintName).grid(row = 0)
button2 = Button(root,text = 'Print Address').grid(row = 0,column = 2)
button2.bind("<Button-1>",PrintAddress)
root.mainloop()
Upvotes: 0
Views: 937
Reputation: 330
Instead of doing:
button2 = Button(root,text = 'Print Address').grid(row = 0, column = 2)
Replace it with
button2 = Button(root,text = 'Print Address')
button2.grid(row = 0, column = 2)
The grid (and pack, and place) function of the Entry object (and of all other widgets) returns None. In python when you do a().b(), the result of the expression is whatever b() returns, therefore Entry(...).grid(...) will return None -Nick
Upvotes: 2