-1

I got an error using gride: "AttributeError: 'NoneType' object has no attribute 'grid'".

This is my code:


    root = tk.Tk()
    root.configure(bg="black")

    # Creates labels
    tk.Label(root, image=logo1).pack()

    # Creates buttons
    tk.Button(root, image=logo2, command=root.destroy).pack().grid(row=0, column=0)
    tk.Button(root, image=logo3, command=root.destroy).pack().grid(row=0, column=0)

    root.mainloop()


וי חנ
  • 79
  • 6

1 Answers1

1

You're using two packing managers in the same time and you're using them wrong.

A pack call will return None, and you're trying to assign grid call to that None.

Do like this:

tk.Button(root, image=logo2, command=root.destroy).grid(row=0, column=0)
tk.Button(root, image=logo3, command=root.destroy).grid(row=0, column=0)

Or with pack manager instead of grid:

tk.Button(root, image=logo2, command=root.destroy).pack()
tk.Button(root, image=logo3, command=root.destroy).pack()
ipaleka
  • 3,745
  • 2
  • 13
  • 33