Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TypeError: 'NoneType' object does not support item assignment?

Tags:

python

tkinter

So I start a root screen with a "file select" and a "go" button. The go button is disabled and I want to make it active after the file has been selected. When I select the file go should become active but instead this error "TypeError: 'NoneType' object does not support item assignment" Here is some sample code

import Tkinter
import tkFileDialog

def chooseDir():
    dir1=tkFileDialog.askopenfilename(parent=root, title='choose file path')
    go['state']=Tkinter.ACTIVE
root=Tkinter.Tk()
global go
go=Tkinter.Button(text='file location',command=chooseDir,state=Tkinter.DISABLED).pack()
root.mainloop()
like image 518
Kosig Avatar asked Feb 17 '26 18:02

Kosig


1 Answers

This line:

go=Tkinter.Button(text='file location',command=chooseDir,state=Tkinter.DISABLED).pack()

is creating a temporary object, then calling pack() on it. The pack method returns None, so go is assigned None.

Remove the .pack() then go will be the Button object. Then call go.pack().

like image 162
Keith Avatar answered Feb 19 '26 07:02

Keith



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!