小编use*_*820的帖子

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

我把按钮放到一个阵列中但是当我打电话给他们时他们不在那里.如果我打印出阵列,我得到:

{0: None, 1: None, 2: None, 3: None, 4: None, 5: None, 6: None, 7: None, ...}
Run Code Online (Sandbox Code Playgroud)

我只是不知道我做错了什么.

from tkinter import *

def main():
    pass

if __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:.... ect


def genABC():
    for …
Run Code Online (Sandbox Code Playgroud)

python dictionary tkinter button

6
推荐指数
1
解决办法
1910
查看次数

标签 统计

button ×1

dictionary ×1

python ×1

tkinter ×1