我有一個函數創建像這樣通過網格()項:(更換while循環使用功能,這應該只是告訴你它是什麼樣子以後)編輯入門
from Tkinter import *
root = Tk()
index=0
while index < 10:
col0 = Text(root,width=20, height=1, bg='white')
col0.grid(row=index,column=0)
col0.insert('0.0',"name")
col1 = Text(root,width=20, height=1, bg='white')
col1.grid(row=index,column=1)
col1.insert('0.0',"attribute #1")
col2 = Text(root,width=20, height=1, bg='white')
col2.grid(row=index,column=2)
col2.insert('0.0',"attribute #2")
col3 = Text(root,width=20, height=1, bg='white')
col3.grid(row=index,column=3)
col3.insert('0.0',"counter")
index+=1
root.mainloop()
所以在特殊事件中調用函數並創建一個新條目(一個新行)。但是如果已經有這個事件的入口,我只想增加計數器。
事件名稱和他們的條目(索引)保存在字典中,所以我確實有行和列,但我現在怎麼能實際訪問col3?
我打算通過col3.get()獲取計數器,但它在每一行都被稱爲col3,所以我怎麼能指定它?
是否可以將col0,col1,col2等放入一種結構(如字典)中,所以通過col0 [name] .insert()...(name是唯一的)訪問它們?我試過,但那並沒有解決(這並不意味着它不可能,我希望,我只是相當新的python)
沒有人有任何建議或解決我的問題嗎?
增加什麼反? – mgilson
使用'作爲範圍(10)中的索引:'而不是索引<10:',而丟失索引= 0和索引+ = 1行,就像一個python指針一樣。 – Jdog