为了账号安全,请及时绑定邮箱和手机立即绑定

为什么我的Tkinter小部件被存储为无?

为什么我的Tkinter小部件被存储为无?

饮歌长啸 2019-07-12 15:33:12
为什么我的Tkinter小部件被存储为无?我把我的按钮放在一个数组中,但当我调用它们时,它们不在那里。如果打印出数组,就会得到:{0: None, 1: None, 2: None, 3: None, 4: None, 5: None, 6: None, 7: None, ...}我只是不知道我做错了什么。from tkinter import *def main():     passif __name__ == '__main__':     main()b={}app = Tk()app.grid()f = Frame(app, bg = "orange", width = 500, height = 500)f.pack(side=BOTTOM, expand = 1)def color(x):    b[x].configure(bg="red") # Error 'NoneType' object has no attribute 'configure'    print(b) # 0: None, 1: None, 2: None, 3: None, 4: None, 5:.... ectdef genABC():     for r in range(3):         for c in range(10):             if (c+(r*10)>25):                 break             print(c+(r*10))             b[c+(r*10)] = Button(f, text=chr(97+c+(r*10)), command=lambda a=c+(r*10): color(a),              borderwidth=1,width=5,bg="white").grid(row=r,column=c)genABC()app.mainloop()
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 276 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信