Python Tkinter按钮小部件行为

时间:2019-12-17 23:55:50

标签: python tkinter

尝试填充充满Light对象的网格。当我单击一个按钮时,它总是打印4而不是坐标。有什么想法吗?

from light import Light
from lights_out import Game
from tkinter import *

game = Game(5, 5)

board = []

root = Tk()
root.minsize(500, 500)
root.maxsize(500, 500)

mainFrame = Frame(root, height=500, width=500, bd=1, relief=RAISED)

def clicked(event):
    print(event.x)


def populateBoard():
    board.append([])
    for i in range(game.width):
        for j in range(game.height):
            light = Light(mainFrame, i, j);
            light.grid(column=i, row=j);
            light.config(width=10, height=5, bg="blue", state="normal", command=lambda: clicked(light));

populateBoard()
mainFrame.pack()

root.mainloop()

0 个答案:

没有答案