0

I'm new to tkinter and trying to figure it out. Why doesn't this work (I get "TypeError: 'NoneType' object does not support item assignment" error)?

import tkinter as tk

def show_entry_fields():
    
    botao['text']='Hello '


master = tk.Tk()
tk.Label(master, text="First Name").grid(row=0)
tk.Label(master, text="Last Name").grid(row=1)




botao=tk.Button(master, text='Show', command=show_entry_fields).grid(row=3, 
                                                               column=1, 
                                                               sticky=tk.W, 
                                                               pady=4)

master.mainloop()
tk.mainloop()

but this does:

from tkinter import *

tkWindow = Tk()  
tkWindow.geometry('400x150')  
tkWindow.title('PythonExamples.org - Tkinter Example')

def changeText():  
    button['text'] = 'Submitted'

button = Button(tkWindow,
    text = 'Submit',
    command = changeText)  
button.pack()  
  
tkWindow.mainloop()
acw1668
  • 40,144
  • 5
  • 22
  • 34
  • Change `botao = tk.Button(...).grid(...)` to `botao = tk.Button(...)` and `botao.grid(...)` – TheLizzard Apr 27 '21 at 15:15
  • Also if you google *"tkinter NoneType"* you get [this](https://stackoverflow.com/questions/1101750/tkinter-attributeerror-nonetype-object-has-no-attribute-attribute-name) which perfectly describes how to fix your problem. – TheLizzard Apr 27 '21 at 15:32

0 Answers0