object has no attribute 'grid'

Fragen zu Tkinter.
Antworten
Lou Cyphr3
User
Beiträge: 59
Registriert: Donnerstag 6. Juli 2017, 00:04

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?]
Cours, camarade, le vieux monde est derrière toi!
__deets__
User
Beiträge: 14493
Registriert: Mittwoch 14. Oktober 2015, 14:29

Du siehst das falsch. pack() gibt None zurück. Du bindest dieses Ergebnis an hello. Und pack mit Grid mischen ist eh nich sinnvoll.
Antworten