用Python用tkinter编程国际象棋游戏。我使用带有64个标签的Tk()作为字段。我也将我的Tk()绑定到一个函数上,该函数通过单击窗口来获取x和y坐标。问题是我重新获得了标签的x和y坐标。 chess game
wn = Tk()
wn.geometry('600x600')
# bind action event
x_click = ''
frame = Frame(master=wn,width=600,height=600)
frame.pack()
def clicked(event):
global x_click
x_click= event.x
print(x_click)
frame.bind("<Button-1>",clicked)
...
class GUI:
def setSpielfeld(self):
# start with index 1,init gamefield with dark and bright fields,x_start and y_start moves the complete gamefield
self.label_gamefields.append('')
for i in range (1,65):
self.label_gamefields.append('')
if self.dasspielfeld.gamecolor[i] == 'dark':
self.label_gamefields[i] = Label(master=wn,image=self.image_dark)
self.label_gamefields[i].place(x=self.dasspielfeld.position_x[i] + x_start,y=self.dasspielfeld.position_y[i] + y_start,width=39,height=39)
else:
self.label_gamefields[i] = Label(master=wn,image=self.image_bright)
self.label_gamefields[i].place(x=self.dasspielfeld.position_x[i] + x_start,height=39)
有人知道该怎么做吗?
非常感谢您