tkinter 'NoneType' object has no attribute 'config'

Question:

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'
Asked By: moron

||

Answers:

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()
Answered By: ex4
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.