Найти - Пользователи
Полная версия: AttributeError: 'NoneType' object has no attribute 'bind'
Начало » Python для новичков » AttributeError: 'NoneType' object has no attribute 'bind'
1
vest01
Помогите пожалуйста. Уже час ломаю голову. Почему он выдает ошибку AttributeError: ‘NoneType’ object has no attribute ‘bind’ ??

КОД:
def add():
    print("Hello")
from tkinter import *    
root = Tk()
but1 = Button(root,
               text = "Добавить авто",width=31,height=1,
               bg="gray",fg="blue"
               ).grid(row = 0, column = 0, sticky = S)
Button(root,
               text = "Удалить авто",width=31,height=1,
               bg="gray",fg="blue"
               ).grid(row = 1, column = 0, sticky = S)
Button(root,
               text = "Редактировать авто",width=31,height=1,
               bg="gray",fg="blue"
               ).grid(row = 0, column = 1, sticky = S)
Button(root,
               text = "Поиск авто",width=31,height=1,
               bg="gray",fg="blue"
               ).grid(row = 1, column = 1, sticky = S)
Button(root,
               text = "Просмотреть список авто",width=64,height=1,
               bg="red",fg="blue"
               ).grid(row = 2, column = 0, columnspan = 2, sticky = W)
root.results_text = Text(root, width = 56, height = 7, wrap = WORD)
root.results_text.grid(row = 3, column = 0, columnspan = 2)
but1.bind("<Button-1>", add)
root.title("Центр продажи автомобилей")
root.geometry("395x175")
root.mainloop()
4kpt_IV
Потому как метод grid возвращает None, а не объект.
Чтобы получить объект, то нужно разнести кнопку и упаковщик в разные строки.

but1 = Button(root,
           text = "Добавить авто",width=31,height=1,
            bg="gray",fg="blue"
            )
but1.grid(row = 0, column = 0, sticky = S)

P.S. По аналогии с методом списков sort()
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Powered by DjangoBB