擅长:python、mysql、java
<p>对于网格上的每个点,您将创建9个按钮并将其中一个放在另一个上。只有最后一个按钮(与3对应的按钮)最终出现,而且每次都会出现。相反,您需要根据<code>c</code>和<code>r</code>计算索引,并且只创建1个按钮:</p>
<pre><code>def num(self):
for c in range(1,4):
for r in range(3):
b = (c - 1) * 3 + r
cmd = lambda b=b: print(b)
self.b= ttk.Button(self, text=b, command=cmd).grid(row = r, column = c, pady = 5)
#print(b)
</code></pre>