python - Why do my Tkinter widgets get stored as None? -


i'm putting buttons array when call them not there. if print out array get:

{0: none, 1: none, 2: none, 3: none, 4: none, 5: none, 6: none, 7: none, ...} 

i don't know doing wrong.

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():     r in range(3):         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() 

the grid, pack, , place methods of every tkinter widget operate in-place , return none. means cannot call them on same line create widget. instead, should called on line below:

widget = ... widget.grid(...)  widget = ... widget.pack(...)  widget = ... widget.place(...) 

so, in code, be:

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") b[c+(r*10)].grid(row=r,column=c) 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -