さて、私が抱えている問題は、押された特定のボタンを参照する方法がわからないことです。私はゲームをやっています。使用者がボタンをクリックすると、それがどの X 座標と Y 座標を持っているか知りたいです。したがって、ボタンのグリッドがあり、1 つをクリックすると、座標が必要になり、そのボタンの色が変更されます。:)
問題: グリッドでどのボタンが押されたかがわかります。
前もって感謝します!
def matris():
for i in range(5):
newButton = Button(app, width = 4, height = 2, bg = "blue",command = lambda i=i: function(i))
newButton.grid(row = i, column = 0)
for i in range(5):
newButton = Button(app, width = 4, height = 2, bg = "blue",command = lambda i=i + 5: function(i))
newButton.grid(row = i, column = 1)
for i in range(5):
newButton = Button(app, width = 4, height = 2, bg = "blue",command = lambda i=i + 10: function(i))
newButton.grid(row = i, column = 2)
for i in range(5):
newButton = Button(app, width = 4, height = 2, bg = "blue",command = lambda i=i + 15: function(i))
newButton.grid(row = i, column = 3)
for i in range(5):
newButton = Button(app, width = 4, height = 2, bg = "blue",command = lambda i=i + 20: function(i))
newButton.grid(row = i, column = 4)
def function(i):
if button 23 was clicked.changeColor to e.g "blue"