Python3.7类型错误:';非类型';对象不支持项分配

Python3.7类型错误:';非类型';对象不支持项分配,python,user-interface,tkinter,Python,User Interface,Tkinter,我使用tkinter模块制作了一个按钮来处理事件,但它不起作用,出现上述错误。我们应该如何解决 我的环境使用的是Python版本3.7,我使用的是Windows 10。编辑器正在使用AtomEditor #-*-coding: utf-8 from tkinter import * def ok(): b1["text"] = "accept" def cancel(): b2["text"] = "확인 됨" def bu3(): b3["text"] = "확인 됨

我使用tkinter模块制作了一个按钮来处理事件,但它不起作用,出现上述错误。我们应该如何解决

我的环境使用的是Python版本3.7,我使用的是Windows 10。编辑器正在使用AtomEditor

#-*-coding: utf-8
from tkinter import *

def ok():
    b1["text"] = "accept"
def cancel():
    b2["text"] = "확인 됨"
def bu3():
    b3["text"] = "확인 됨"
def bu4():
    b4["text"] = "확인 됨"

window = Tk()
b1 = Button(window, text="버튼 1", command=ok).pack()
b2 = Button(window, text="버튼 2", command=cancel).pack()
b3 = Button(window, text="버튼 3", command=bu3).pack()
b4 = Button(window, text="버튼 4", command=bu4).pack()

window.mainloop()
试试这个:

b1 = Button(window, text="버튼 1", command=ok)
b2 = Button(window, text="버튼 2", command=cancel)
b3 = Button(window, text="버튼 3", command=bu3)
b4 = Button(window, text="버튼 4", command=bu4)
b1.pack()
b2.pack()
b3.pack()
b4.pack()
或者更好:

b1 = Button(window, text="버튼 1", command=ok)
b2 = Button(window, text="버튼 2", command=cancel)
b3 = Button(window, text="버튼 3", command=bu3)
b4 = Button(window, text="버튼 4", command=bu4)
for c in sorted(window.children):
    window.children[c].pack()

您需要拆分每个按钮并将其打包为两条语句:

b1=按钮(窗口,文本=”버튼 1“,命令=正常)

b1.pack()

因为您希望将按钮分配给b1,而不是分组调用的结果(无)