Seite 1 von 1

object has no attribute 'grid'

Verfasst: Freitag 23. Oktober 2020, 16:58
von Lou Cyphr3
hallo,

ich möchte mit tkinter eine gui schreiben und habe gerade folgendes Problem.

Code: Alles auswählen

import tkinter as tk

root = tk.Tk()


canvas = tk.Canvas(root, height=700, width=700, bg="blue").pack()
frame = tk.Frame(root, bg="white")
frame.place(relwidt=0.8, relheight=0.8, relx=0.1, rely=0.1)


hello = tk.Button(root, text="test", padx=100, pady=5, ).pack()
hello.grid(row=2, column=2)

root.mainloop()
fehler:

Code: Alles auswählen

 hello.grid(row=2, column=2)
AttributeError: 'NoneType' object has no attribute 'grid'

Wieso nicht? hello ist doch eine Instanz von Button oder sehe ich das flasch?]

Re: object has no attribute 'grid'

Verfasst: Freitag 23. Oktober 2020, 17:29
von __deets__
Du siehst das falsch. pack() gibt None zurück. Du bindest dieses Ergebnis an hello. Und pack mit Grid mischen ist eh nich sinnvoll.