类型错误:'NoneType'对象不支持项目分配?

编程入门 行业动态 更新时间:2024-10-24 14:22:27
本文介绍了类型错误:'NoneType'对象不支持项目分配?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

所以我用文件选择"和去"按钮启动一个根屏幕.转到按钮已禁用,我想在选择文件后将其激活.当我选择文件时,go 应该变为活动状态,而是出现此错误TypeError:'NoneType' 对象不支持项目分配"这是一些示例代码

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()

推荐答案

这一行:

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

正在创建一个临时对象,然后对其调用 pack().pack 方法返回 None,所以 go 被分配了 None.

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

删除 .pack() 然后 go 将成为 Button 对象.然后调用go.pack().

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

这篇关于类型错误:'NoneType'对象不支持项目分配?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 08:11:37,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1391404.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不支持   分配   对象   错误   类型

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!