1 '''
2 2048GUI3 '''
4 importtkinter5 importrandom6
7 classGui2048:8 def __init__(self): #显示窗体
9 self.data = [[0 for i in range(4)] for j in range(4)]10 self.scores =011 self.window =tkinter.Tk()12 self.window.title("2048")13
14 self.window.bind("", self.fangxiangEvent)15
16 self.canvasDa =tkinter.Canvas(self.window,17 width=400,18 height=400,19 bg="white")20 self.canvasDa.pack()21
22 frame =tkinter.Frame(self.window)23 frame.pack()24
25 self.buttonL =tkinter.Button(frame,26 text = "左",27 command = self.bleft).grid(row = 1, column = 1)28 self.buttonR =tkinter.Button(frame,29 text="右",30 command=self.bright).grid(row=1, column=2)31 self.buttonU =tkinter.Button(frame,32 text="上",33 command=self.bup).grid(row=1, column=3)3