'NoneType' object has no attribute 'bind'

Discussion in 'Python' started by Alex, Oct 28, 2010.

  1. Alex

    Alex Guest

    hi there, I keep getting the message in the Topic field above.

    Here's my code:

    self.click2=Button(root,text="Click Me").grid(column=4,row=10)
    self.click2.bind("<Button-1>",self.pop2pop)

    def pop2pop(self,event):

    print("Adsfadsf")
    newpop=IntVar()
    newpop=self.PopSize.get();


    what am I doing wrong?

    cheers,

    Alex
     
    Alex, Oct 28, 2010
    #1
    1. Advertising

  2. Alex

    Peter Otten Guest

    Alex wrote:

    > hi there, I keep getting the message in the Topic field above.
    >
    > Here's my code:
    >
    > self.click2=Button(root,text="Click Me").grid(column=4,row=10)


    Replace the above line to

    button = Button(root, text="Click Me")
    print "Button() returns", button
    grid = button.grid(column=4, row=10)
    print ".grid() returns", grid
    self.click2 = button

    and be enlighted. Then remove the print statements.

    > self.click2.bind("<Button-1>",self.pop2pop)
    >
    > def pop2pop(self,event):
    >
    > print("Adsfadsf")
    > newpop=IntVar()
    > newpop=self.PopSize.get();
    >
    >
    > what am I doing wrong?


    If one step doesn't work try to replace it with smaller steps and add print
    statements to find the part that doesn't do what you expected.

    Peter
     
    Peter Otten, Oct 28, 2010
    #2
    1. Advertising

  3. Alex

    Alex Willmer Guest

    On Oct 28, 11:24 am, Alex <> wrote:
    > hi there, I keep getting the message in the Topic field above.
    >
    > Here's my code:
    >
    > self.click2=Button(root,text="Click Me").grid(column=4,row=10)
    > self.click2.bind("<Button-1>",self.pop2pop)


    From reading the Tkinter docs grid doesn't itself return a control. So
    I think you want this:

    self.click2 = Button(root, text="Click Me")
    self.click2.grid(column=4, row=10)
    self.click2.bind("<Button-1>", self.pop2pop)

    However, that's totally untested so don't take it as gospel.

    > def pop2pop(self,event):
    >
    >         print("Adsfadsf")
    >         newpop=IntVar()
    >         newpop=self.PopSize.get();
    >
    > what am I doing wrong?
    >
    > cheers,
    >
    > Alex
     
    Alex Willmer, Oct 28, 2010
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jordan Harry
    Replies:
    1
    Views:
    516
    Sean DiZazzo
    May 2, 2008
  2. globalrev
    Replies:
    12
    Views:
    569
    J. Cliff Dyer
    May 16, 2008
  3. MRAB
    Replies:
    0
    Views:
    878
  4. Dave Angel
    Replies:
    0
    Views:
    168
    Dave Angel
    Aug 2, 2012
  5. Prasad, Ramit

    RE: attribute is accessed from Nonetype

    Prasad, Ramit, Aug 3, 2012, in forum: Python
    Replies:
    0
    Views:
    167
    Prasad, Ramit
    Aug 3, 2012
Loading...

Share This Page