Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

tkinter 'NoneType' object has no attribute 'config'

I got an error for AttributeError: ‘NoneType’ object has no attribute ‘config’ when I run a Treasure Island game I created (very original). I’ve looked at other posts about this and tried the same thing to no solution, anyway, here’s the code:

import tkinter
window = tkinter.Tk()

window.title("Treasure Island")
window.geometry("500x500")

text = tkinter.Label(window, text='''
          |                   |                  |                     |
 _________|________________.=""_;=.______________|_____________________|_______
|                   |  ,-"_,=""     `"=.|                  |
|___________________|__"=._o`"-._        `"=.______________|___________________
          |                `"=._o`"=._      _`"=._                     |
 _________|_____________________:=._o "=._."_.-="'"=.__________________|_______
|                   |    __.--" , ; `"=._o." ,-"""-._ ".   |
|___________________|_._"  ,. .` ` `` ,  `"-._"-._   ". '__|___________________
          |           |o`"=._` , "` `; .". ,  "-._"-._; ;              |
 _________|___________| ;`-.o`"=._; ." ` '`."\` . "-._ /_______________|_______
|                   | |o;    `"-.o`"=._``  '` " ,__.--o;   |
|___________________|_| ;     (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._    "      `".o|o_.--"    ;o;____/______/______/____
/______/______/______/_"=._o--._        ; | ;        ; ;/______/______/______/_
____/______/______/______/__"=._o--._   ;o|o;     _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/_____ /
''')

text.pack()
text = text.config(font=('length',15))

line1 = tkinter.Label(window, text="Welcome to Treasure Island,\n"
                                   "Your goal is to find the buried Treasure!")

line1.pack()
line1 = text.config(font=('length',15))

window.mainloop()

Exact error:

    line1 = text.config(font=('length',15))
AttributeError: 'NoneType' object has no attribute 'config'

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should check this from tkinter documents, but I suppose that tkinter.Label().config() -method does not return anything (or put it another words, it returns None).

text.pack()

## Here you set text as return value from config method
# text = text.config(font=('length',15))
## Try this intestad
text.config(font=('length',15))

line1 = tkinter.Label(window, text="Welcome to Treasure Island,\n"
                                  "Your goal is to find the buried Treasure!")

line1.pack()

## Here you try to re-use the value which is None
#line1 = text.config(font=('length',15))
## Try this instead

line1.config(font=('length',15))

window.mainloop()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading