我是Python和编程的新手,我正在努力使此代码正常工作...
没有找到其他方法
import Tkinter
def push_move(sqq):
print(sqq)
cb_list = [['green', 0, 'a1', 'a1', 7, 0, 5, 'x', 'y', 'z'],
['white', 1, 'b1', 'b1', 7, 1, 5, 'x', 'y', 'z'],
['green', 2, 'c1', 'c1', 7, 2, 5, 'x', 'y', 'z'],
['white', 3, 'd1', 'd1', 7, 3, 5, 'x', 'y', 'z'],
['green', 4, 'e1', 'e1', 7, 4, 5, 'x', 'y', 'z'],
['white', 5, 'f1', 'f1', 7, 5, 5, 'x', 'y', 'z'],
['green', 6, 'g1', 'g1', 7, 6, 5, 'x', 'y', 'z'],
['white', 7, 'h1', 'h1', 7, 7, 5, 'x', 'y', 'z'],
['white', 10, 'a2', 'a2', 6, 0, 5, 'x', 'y', 'z'],
['green', 11, 'b2', 'b2', 6, 1, 10, 'x', 'y', 'z'],
['white', 12, 'c2', 'c2', 6, 2, 10, 'x', 'y', 'z'],
['green', 13, 'd2', 'd2', 6, 3, 10, 'x', 'y', 'z'],
['white', 14, 'e2', 'e2', 6, 4, 10, 'x', 'y', 'z'],
['green', 15, 'f2', 'f2', 6, 5, 10, 'x', 'y', 'z'],
['white', 16, 'g2', 'g2', 6, 6, 10, 'x', 'y', 'z'],
['green', 17, 'h2', 'h2', 6, 7, 5, 'x', 'y', 'z'],
['green', 20, 'a3', 'a3', 5, 0, 5, 'x', 'y', 'z'],
['white', 21, 'b3', 'b3', 5, 1, 10, 'x', 'y', 'z'],
['green', 22, 'c3', 'c3', 5, 2, 15, 'x', 'y', 'z'],
['white', 23, 'd3', 'd3', 5, 3, 15, 'x', 'y', 'z'],
['green', 24, 'e3', 'e3', 5, 4, 15, 'x', 'y', 'z'],
['white', 25, 'f3', 'f3', 5, 5, 15, 'x', 'y', 'z'],
['green', 26, 'g3', 'g3', 5, 6, 10, 'x', 'y', 'z'],
['white', 27, 'h3', 'h3', 5, 7, 5, 'x', 'y', 'z'],
['white', 30, 'a4', 'a4', 4, 0, 5, 'x', 'y', 'z'],
['green', 31, 'b4', 'b4', 4, 1, 10, 'x', 'y', 'z'],
['white', 32, 'c4', 'c4', 4, 2, 15, 'x', 'y', 'z'],
['green', 33, 'd4', 'd4', 4, 3, 20, 'x', 'y', 'z'],
['white', 34, 'e4', 'e4', 4, 4, 20, 'x', 'y', 'z'],
['green', 35, 'f4', 'f4', 4, 5, 15, 'x', 'y', 'z'],
['white', 36, 'g4', 'g4', 4, 6, 10, 'x', 'y', 'z'],
['green', 37, 'h4', 'h4', 4, 7, 5, 'x', 'y', 'z'],
['green', 40, 'a5', 'a5', 3, 0, 5, 'x', 'y', 'z'],
['white', 41, 'b5', 'b5', 3, 1, 10, 'x', 'y', 'z'],
['green', 42, 'c5', 'c5', 3, 2, 15, 'x', 'y', 'z'],
['white', 43, 'd5', 'd5', 3, 3, 20, 'x', 'y', 'z'],
['green', 44, 'e5', 'e5', 3, 4, 20, 'x', 'y', 'z'],
['white', 45, 'f5', 'f5', 3, 5, 15, 'x', 'y', 'z'],
['green', 46, 'g5', 'g5', 3, 6, 10, 'x', 'y', 'z'],
['white', 47, 'h5', 'h5', 3, 7, 5, 'x', 'y', 'z'],
['white', 50, 'a6', 'a6', 2, 0, 5, 'x', 'y', 'z'],
['green', 51, 'b6', 'b6', 2, 1, 10, 'x', 'y', 'z'],
['white', 52, 'c6', 'c6', 2, 2, 15, 'x', 'y', 'z'],
['green', 53, 'd6', 'd6', 2, 3, 15, 'x', 'y', 'z'],
['white', 54, 'e6', 'e6', 2, 4, 15, 'x', 'y', 'z'],
['green', 55, 'f6', 'f6', 2, 5, 15, 'x', 'y', 'z'],
['white', 56, 'g6', 'g6', 2, 6, 10, 'x', 'y', 'z'],
['green', 57, 'h6', 'h6', 2, 7, 5, 'x', 'y', 'z'],
['green', 60, 'a7', 'a7', 1, 0, 5, 'x', 'y', 'z'],
['white', 61, 'b7', 'b7', 1, 1, 10, 'x', 'y', 'z'],
['green', 62, 'c7', 'c7', 1, 2, 10, 'x', 'y', 'z'],
['white', 63, 'd7', 'd7', 1, 3, 10, 'x', 'y', 'z'],
['green', 64, 'e7', 'e7', 1, 4, 10, 'x', 'y', 'z'],
['white', 65, 'f7', 'f7', 1, 5, 10, 'x', 'y', 'z'],
['green', 66, 'g7', 'g7', 1, 6, 10, 'x', 'y', 'z'],
['white', 67, 'h7', 'h7', 1, 7, 5, 'x', 'y', 'z'],
['white', 70, 'a8', 'a8', 0, 0, 5, 'x', 'y', 'z'],
['green', 71, 'b8', 'b8', 0, 1, 5, 'x', 'y', 'z'],
['white', 72, 'c8', 'c8', 0, 2, 5, 'x', 'y', 'z'],
['green', 73, 'd8', 'd8', 0, 3, 5, 'x', 'y', 'z'],
['white', 74, 'e8', 'e8', 0, 4, 5, 'x', 'y', 'z'],
['green', 75, 'f8', 'f8', 0, 5, 5, 'x', 'y', 'z'],
['white', 76, 'g8', 'g8', 0, 6, 5, 'x', 'y', 'z'],
['green', 77, 'h8', 'h8', 0, 7, 5, 'x', 'y', 'z']]
mw = tkinter.Tk()
mw.geometry("560x595+50+50")
mw.minsize(width=560, height=560)
mw.maxsize(width=560, height=560)
mw.title("Chess Partner 2020")
for f in range(8):
mw.columnconfigure(f, weight=10)
for r in range(8):
mw.rowconfigure(r, weight=10)
mw.rowconfigure(8, weight=5)
for i in range(64):
cb_list[i][3] = tkinter.Frame(mw)
cb_list[i][3].grid(row=cb_list[i][4], column=cb_list[i][5])
cb_list[i][3].config(background=cb_list[i][0], width=70, height=70)
cb_list[i][3].rowconfigure(0, minsize=70)
cb_list[i][3].columnconfigure(0, minsize=70)
cb_list[i][9] = tkinter.Button(cb_list[i][3], background=cb_list[i][0],
border=0, command=lambda: push_move(cb_list[i][1])) \
.grid(row=0, column=0, columnspan=1, rowspan=1, sticky='nsew')
button_frame = tkinter.Frame(mw)
button_frame.grid(row=8, column=0, rowspan=1, columnspan=8, sticky='nsew')
button_frame.config(background='lightgreen', height=35)
button_frame.columnconfigure(0, weight=3)
button_frame.columnconfigure(1, weight=3)
button_frame.columnconfigure(2, weight=3)
button_frame.columnconfigure(3, weight=3)
button_frame.rowconfigure(0, weight=1)
# Defining Buttons
tkinter.Button(button_frame, text='Next Move', font='arial 15')\
.grid(row=0, column=0, columnspan=1, sticky='nsew')
tkinter.Button(button_frame, text='Save Postion', font='arial 12')\
.grid(row=0, column=1, columnspan=1, sticky='nsew')
tkinter.Button(button_frame, text='Play', font='arial 15', background='yellow')\
.grid(row=0, column=2, columnspan=1, sticky='nsew')
tkinter.Button(button_frame, text='QUIT', font='arial 15')\
.grid(row=0, column=3, columnspan=1, sticky='nsew')
mw.mainloop()
当出现UI屏幕,并且通过单击按钮调用命令push_move(cb_list[i][9])
时,.... i
的值更改为上次使用的值,而我没有得到相同的值在循环中分配的
for i in range(64):