【发布时间】:2018-04-24 16:00:33
【问题描述】:
使用此代码,框显示全 0。我不确定为什么它没有在列表中显示序列。它应该在 [0,0] 的位置显示“1”,在 [0,1] 的位置显示“3”,在 [0,2] 的位置显示“2”……以此类推,直到填满所有 9 个数字在 9 个盒子里。
import tkinter as tk
the_list = (1, 3, 2, 4, 12, 56, 7, 10, 19)
var_categories = {}
def main():
root = tk.Tk()
root.title("class basic window")
root.geometry("500x300")
root.config(background="LightBlue4")
app = Application(root)
root.mainloop()
class Application(tk.Frame):
def __init__(self, parent):
tk.Frame.__init__(self, parent, bg="ivory2", bd=2, relief=tk.RAISED)
self.parent = parent
self.pack(fill=tk.BOTH, expand=1)
self.initUI()
def initUI(self):
iterator = iter(the_list)
for r in range(3):
for c in range(3):
item = next(iterator)
self.labelVariable = tk.IntVar()
self.label = tk.Label(self, textvariable=self.labelVariable, relief="ridge",width=8, height=3 )
self.label.grid(row=r, column=c, sticky='news')
var_categories[item] = self.labelVariable
if __name__ == '__main__':
main()
【问题讨论】:
标签: python matrix tkinter labels