וי חנ
וי חנ

Reputation: 79

"AttributeError" using mainloop() function

I got an error that says: "AttributeError: 'NoneType' object has no attribute 'mainloop'"

I wrote my first GUI in python but I got an error using the mainloop function.

import tkinter as tk

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


def main():
    logo1 = tk.PhotoImage(file="C:\Logo1.png")
    logo2 = tk.PhotoImage(file="C:\Logo2.png")
    logo3 = tk.PhotoImage(file="C:\Logo3.png")

    # Creates labels
    lab1 = tk.Label(root, image=logo1).pack()
    lab2 = tk.Label(root, image=logo2).pack()
    lab3 = tk.Label(root, image=logo3).pack()

    root.mainloop()


if __name__ == "__main__":
    main()

Upvotes: 0

Views: 236

Answers (2)

Sushant
Sushant

Reputation: 3669

You need to do something like this -

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

And rest remains the same. The error is because the result of configure is None and NoneType has no attribute called mainloop.

Upvotes: 2

Norrius
Norrius

Reputation: 7920

The .configure() method doesn't return anything (i.e. implicitly returns None). Try this instead:

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

Upvotes: 3

Related Questions