我正在尝试以用户指定的大小初始化一个蓝色矩形网格。但是,矩形并未在初始化的画布上绘制。我正在尝试将它们存储在矩阵中以供以后操作。我的代码如下:
import Tkinter
import sys
from math import floor
master = Tkinter.Tk()
xboxes = int(sys.argv[1])
yboxes = int(sys.argv[2])
winx = 800
winy = 600
w = Tkinter.Canvas(master, width=winx, height=winy)
squares = [[None]*5 for i in range(5)]
w.pack()
for i in range(yboxes):
for j in range(xboxes):
initx = floor(winx / xboxes * j)
inity = floor(winy / yboxes * i)
sizex = floor(winx / xboxes * j)
sizey = floor(winy / yboxes * i)
squares[i][j] = w.create_rectangle(initx, inity, sizex, sizey, fill="red")
master.mainloop()
知道为什么它不起作用吗?任何帮助将非常感激。