### ex4-1 ### import tkinter # 匯入 tkinter 模組 mouse_x = 0 # 滑鼠游標的 x 座標 mouse_y = 0 # 滑鼠游標的 y 座標 mouse_c = 0 # 點選滑鼠按鍵時的變數 (旗標) def mouse_move(e): # 移動滑鼠時執行的函式 global mouse_x, mouse_y # 將滑鼠的座標變數 mouse_x, mouse_y,設成全域變數 mouse_x = e.x # 將滑鼠的 x 座標帶入 mouse_x mouse_y = e.y # 將滑鼠的 y 座標帶入 mouse_y def mouse_press(e): # 點選滑鼠時執行的函式 global mouse_c # 將滑鼠的旗標 mouse_c 設成全域變數 mouse_c = 1 # 將 1 帶入 mouse_c (1: 代表點選) def mouse_release(e): # 放開滑鼠時執行的函式 global mouse_c mouse_c = 0 # 將 0 帶入 mouse_c (0: 代表放開) def game_main(): # 執行即時處理的函式 fnt = ('Times New Roman', 30) # 指定字型的變數 txt = 'mouse({}, {}){}'.format(mouse_x, mouse_y, mouse_c) # 要顯示的字串 (滑鼠專用變數的值) cvs.delete('TEST') # 先刪除字串 cvs.create_text(456, 384, text = txt, fill = 'black', font = fnt, tag = 'TEST') # 在畫布顯示字串 root.after(100, game_main) # 在 0.1 秒後再次執行這個函式 root = tkinter.Tk() # 建立視窗物件 root.title('滑鼠輸入處理') # 指定標題 root.resizable(False, False) # 禁止改變視窗大小 root.bind('', mouse_move) # 指定移動滑鼠時執行的函式 root.bind('', mouse_press) # 指定點選滑鼠時執行的函式 root.bind('', mouse_release) # 指定放開滑鼠時執行的函式 cvs = tkinter.Canvas(root, width = 912, height = 768) # 建立畫布 cvs.pack() # 配置畫布 game_main() # 呼叫主要處理的函式 root.mainloop() # 顯示視窗 ### ex4-2 ### import tkinter cursor_x = 0 # 滑鼠游標的水平位置 (位於從左側數來第幾格) cursor_y = 0 # 滑鼠游標的垂直位置 (位於從上方數來第幾格) mouse_x = 0 # 滑鼠游標的 x 座標 mouse_y = 0 # 滑鼠游標的 y 座標 def mouse_move(e): # 移動滑鼠時執行的函式 global mouse_x, mouse_y mouse_x = e.x mouse_y = e.y def game_main(): # 執行即時處理的函式 global cursor_x, cursor_y if 24 <= mouse_x and mouse_x < 24 + 72 * 8 and 24 <= mouse_y and mouse_y < 24 + 72 * 10: # 假設滑鼠游標的座標位置位於遊戲介面之內 cursor_x = int((mouse_x - 24) / 72) # 根據滑鼠游標的 x 座標計算遊戲游標的水平位置 cursor_y = int((mouse_y - 24) / 72) # 根據滑鼠游標的 y 座標計算遊戲游標的垂直位置 cvs.delete('CURSOR') # 消除遊戲游標 cvs.create_image(cursor_x * 72 + 60, cursor_y * 72 + 60, image = cursor, tag = 'CURSOR') # 於新的位置顯示遊戲游標 root.after(100, game_main) root = tkinter.Tk() root.title('顯示遊戲游標') root.resizable(False, False) root.bind('', mouse_move) cvs = tkinter.Canvas(root, width = 912, height = 768) cvs.pack() bg = tkinter.PhotoImage(file = 'images/cat_bg.png') cursor = tkinter.PhotoImage(file = 'images/cat_cursor.png') cvs.create_image(456, 384, image = bg) game_main() root.mainloop() ### ex4-3 ### import tkinter cat = [ # 管理格子的二維 list [1, 0, 0, 0, 0, 0, 7, 7], [0, 2, 0, 0, 0, 0, 7, 7], [0, 0, 3, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 2, 3, 4, 5, 6] ] def draw_cat(): # 顯示貓咪的函式 for y in range(10): # 走 y (列) for x in range(8): # 走 x (行) if cat[y][x] > 0: # 格子的值若大於 0,則以格子的值做為索引,取得 img_cat 裡的圖片 cvs.create_image(x * 72 + 60, y * 72 + 60, image = img_cat[cat[y][x]]) root = tkinter.Tk() root.title('利用二維列表管理格子') root.resizable(False, False) cvs = tkinter.Canvas(root, width = 912, height = 768) cvs.pack() bg = tkinter.PhotoImage(file = 'images/cat_bg.png') img_cat = [ None, tkinter.PhotoImage(file = 'images/cat1.png'), tkinter.PhotoImage(file = 'images/cat2.png'), tkinter.PhotoImage(file = 'images/cat3.png'), tkinter.PhotoImage(file = 'images/cat4.png'), tkinter.PhotoImage(file = 'images/cat5.png'), tkinter.PhotoImage(file = 'images/cat6.png'), tkinter.PhotoImage(file= 'images/cat_paw.png') ] cvs.create_image(456, 384, image = bg) # 在畫布繪製背景,設置背景圖片的中心點 draw_cat() # 呼叫顯示貓咪的函式 root.mainloop() ### ex4-4 ### import tkinter cat = [ [1, 0, 0, 0, 0, 0, 1, 2], [0, 2, 0, 0, 0, 0, 3, 4], [0, 0, 3, 0, 0, 0, 0, 0], [0, 0, 0, 4, 0, 0, 0, 0], [0, 0, 0, 0, 5, 0, 0, 0], [0, 0, 0, 0, 0, 6, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 1, 2, 3, 4, 0, 0] ] def draw_cat(): # 顯示貓咪的函式 for y in range(10): for x in range(8): if cat[y][x] > 0: # 若 list 的元素大於 0 cvs.create_image(x * 72 + 60, y * 72 + 60, image = img_cat[cat[y][x]], tag = 'CAT') # 則顯示貓咪圖片 def drop_cat(): # 讓貓咪落下的函式 for y in range(8, -1, -1): for x in range(8): if cat[y][x] != 0 and cat[y + 1][x] == 0: # 若貓咪底下的格子為空白 cat[y + 1][x] = cat[y][x] # 在空白處顯示貓咪圖案 cat[y][x] = 0 # 讓原本的貓咪消失 def game_main(): # 執行主要處理 (即時處理) 的函式 drop_cat() # 呼叫讓貓咪落下的函式 cvs.delete('CAT') # 刪除貓咪 draw_cat() # 呼叫顯示貓咪的函式 root.after(100, game_main) root = tkinter.Tk() root.title('讓貓咪落下') root.resizable(False, False) cvs = tkinter.Canvas(root, width = 912, height = 768) cvs.pack() bg = tkinter.PhotoImage(file = 'images/cat_bg.png') img_cat = [ None, tkinter.PhotoImage(file = 'images/cat1.png'), tkinter.PhotoImage(file = 'images/cat2.png'), tkinter.PhotoImage(file = 'images/cat3.png'), tkinter.PhotoImage(file = 'images/cat4.png'), tkinter.PhotoImage(file = 'images/cat5.png'), tkinter.PhotoImage(file = 'images/cat6.png'), tkinter.PhotoImage(file= 'images/cat_paw.png') ] cvs.create_image(456, 384, image = bg) game_main() root.mainloop() ### ex4-5 ### import tkinter import random cursor_x = 0 # 滑鼠游標的水平位置 (位於從左側數來第幾格) cursor_y = 0 # 滑鼠游標的垂直位置 (位於從上方數來第幾格) mouse_x = 0 # 滑鼠游標的 x 座標 mouse_y = 0 # 滑鼠游標的 y 座標 mouse_c = 0 # 點選滑鼠按鍵時的變數 (旗標) def mouse_move(e): # 移動滑鼠時執行的函式 global mouse_x, mouse_y mouse_x = e.x mouse_y = e.y def mouse_press(e): # 點選滑鼠時執行的函式 global mouse_c mouse_c = 1 cat = [ # 管理格子的二維 list [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0] ] def draw_cat(): # 顯示貓咪的函式 for y in range(10): for x in range(8): if cat[y][x] > 0: cvs.create_image(x * 72 + 60, y * 72 + 60, image = img_cat[cat[y][x]], tag = 'CAT') def drop_cat(): # 讓貓咪落下的函式 for y in range(8, -1, -1): for x in range(8): if cat[y][x] != 0 and cat[y + 1][x] == 0: # 若貓咪底下的格子為空白 cat[y + 1][x] = cat[y][x] # 在空白處顯示貓咪圖案 cat[y][x] = 0 # 讓原本的貓咪消失 def game_main(): # 執行主要處理 (即時處理) 的函式 global cursor_x, cursor_y, mouse_c drop_cat() # 呼叫讓貓咪落下的函式 if 24 <= mouse_x and mouse_x < 24 + 72 * 8 and 24 <= mouse_y and mouse_y < 24 + 72 * 10: # 如果滑鼠游標在遊戲畫面裡 cursor_x = int((mouse_x - 24) / 72) # 根據滑鼠游標的 x 座標計算滑鼠游標的水平位置 cursor_y = int((mouse_y - 24) / 72) # 根據滑鼠游標的 y 座標計算滑鼠游標的水平位置 if mouse_c == 1: # 若玩家按下滑鼠左鍵 mouse_c = 0 # 解除代表按鍵按下的旗標 cat[cursor_y][cursor_x] = random.randint(1, 6) # 在滑鼠所在的位置隨機配置貓咪 cvs.delete('CURSOR') # 消除遊戲游標 cvs.create_image(cursor_x * 72 + 60, cursor_y * 72 + 60, image = cursor, tag = 'CURSOR') # 在新的位置顯示遊戲游標 cvs.delete('CAT') # 刪除貓咪圖片 draw_cat() # 顯示貓咪 root.after(100, game_main) root = tkinter.Tk() root.title('點選後配置貓咪') root.resizable(False, False) root.bind('', mouse_move) root.bind('', mouse_press) cvs = tkinter.Canvas(root, width = 912, height = 768) cvs.pack() bg = tkinter.PhotoImage(file = 'images/cat_bg.png') cursor = tkinter.PhotoImage(file = 'images/cat_cursor.png') img_cat = [ None, tkinter.PhotoImage(file = 'images/cat1.png'), tkinter.PhotoImage(file = 'images/cat2.png'), tkinter.PhotoImage(file = 'images/cat3.png'), tkinter.PhotoImage(file = 'images/cat4.png'), tkinter.PhotoImage(file = 'images/cat5.png'), tkinter.PhotoImage(file = 'images/cat6.png'), tkinter.PhotoImage(file= 'images/cat_paw.png') ] cvs.create_image(456, 384, image = bg) game_main() root.mainloop() ### ex4-6 ### import tkinter import random cursor_x = 0 cursor_y = 0 mouse_x = 0 mouse_y = 0 mouse_c = 0 def mouse_move(e): global mouse_x, mouse_y mouse_x = e.x mouse_y = e.y def mouse_press(e): global mouse_c mouse_c = 1 cat = [] # 管理格子的二維 list for i in range(10): # 透過迴圈與 append() 方法初始化二維 list cat.append([0, 0, 0, 0, 0, 0, 0, 0]) def draw_cat(): # 顯示貓咪的函式 for y in range(10): for x in range(8): if cat[y][x] > 0: cvs.create_image(x * 72 + 60, y * 72 + 60, image = img_cat[cat[y][x]], tag = 'CAT') def linein_cat(): # 判斷貓咪是否水平連成一線的函式 for y in range(10): for x in range(1, 7): if cat[y][x] > 0: # 若格子裡有貓咪 if cat[y][x - 1] == cat[y][x] and cat[y][x + 1] == cat[y][x]: # 而且左右 (水平) 格子裡有貓咪 cat[y][x - 1] = 7 # 讓貓咪變肉球 cat[y][x] = 7 # 讓貓咪變肉球 cat[y][x + 1] = 7 # 讓貓咪變肉球 def game_main(): global cursor_x, cursor_y, mouse_c if 660 <= mouse_x and mouse_x < 840 and 100 <= mouse_y and mouse_y < 160 and mouse_c == 1: # 點選氣球的測試之後 mouse_c = 0 # 解除旗標 linein_cat() # 呼叫判斷貓咪是否水平連成一線的函式 if 24 <= mouse_x and mouse_x < 24 + 72 * 8 and 24 <= mouse_y and mouse_y < 24 + 72 * 10: # 如果滑鼠游標在遊戲畫面裡 cursor_x = int((mouse_x - 24) / 72) cursor_y = int((mouse_y- 24) / 72) if mouse_c == 1: mouse_c = 0 cat[cursor_y][cursor_x] = random.randint(1, 2) cvs.delete('CURSOR') cvs.create_image(cursor_x * 72 + 60, cursor_y * 72 + 60, image = cursor, tag= 'CURSOR') cvs.delete('CAT') draw_cat() root.after(100, game_main) root = tkinter.Tk() root.title('是否水平連成一線呢?') root.resizable(False, False) root.bind('', mouse_move) root.bind('', mouse_press) cvs = tkinter.Canvas(root, width = 912, height = 768) cvs.pack() bg = tkinter.PhotoImage(file = 'images/cat_bg.png') cursor = tkinter.PhotoImage(file = 'images/cat_cursor.png') img_cat = [ None, tkinter.PhotoImage(file = 'images/cat1.png'), tkinter.PhotoImage(file = 'images/cat2.png'), tkinter.PhotoImage(file = 'images/cat3.png'), tkinter.PhotoImage(file = 'images/cat4.png'), tkinter.PhotoImage(file = 'images/cat5.png'), tkinter.PhotoImage(file = 'images/cat6.png'), tkinter.PhotoImage(file= 'images/cat_paw.png') ] cvs.create_image(456, 384, image = bg) cvs.create_rectangle(660, 100, 840, 160, fill = 'white') cvs.create_text(750, 130, text = '測試', fill = 'red', font = ('Times New Roman', 30)) game_main() root.mainloop() ### ex4-7 ### import tkinter import random cursor_x = 0 cursor_y = 0 mouse_x = 0 mouse_y = 0 mouse_c = 0 def mouse_move(e): global mouse_x, mouse_y mouse_x = e.x mouse_y = e.y def mouse_press(e): global mouse_c mouse_c = 1 cat = [] # 管理格子的二維 list check = [] # 判斷專用的二維 list for i in range(10): # 透過迴圈與 list 的 append() 初始化 list cat.append([0, 0, 0, 0, 0, 0, 0, 0]) check.append([0, 0, 0, 0, 0, 0, 0, 0]) def draw_cat(): for y in range(10): for x in range(8): if cat[y][x] > 0: cvs.create_image(x * 72 + 60, y * 72 + 60, image = img_cat[cat[y][x]], tag = 'CAT') def check_cat(): # 判斷水平、垂直、傾斜的貓咪連成一線的函式 for y in range(10): # 將貓咪的值 (管理格子的二維 list) 複製到判斷專用的 list for x in range(8): check[y][x] = cat[y][x] for y in range(1, 9): for x in range(8): if check[y][x] > 0: if check[y - 1][x] == check[y][x] and check[y + 1][x] == check[y][x]: # 若上下是相同貓咪,將上下格子裡的貓變成肉球 cat[y - 1][x] = 7 cat[y][x] = 7 cat[y + 1][x] = 7 for y in range(10): for x in range(1, 7): if check[y][x] > 0: if check[y][x - 1] == check[y][x] and check[y][x + 1] == check[y][x]: # 若左右是相同貓咪,將左右格子裡的貓變成肉球 cat[y][x - 1] = 7 cat[y][x] = 7 cat[y][x + 1] = 7 for y in range(1, 9): for x in range(1, 7): if check[y][x] > 0: if check[y - 1][x - 1] == check[y][x] and check[y + 1][x + 1] == check[y][x]: # 若左上與右下是相同貓咪,將左上與右下格子裡的貓變成肉球 cat[y - 1][x - 1] = 7 cat[y][x] = 7 cat[y + 1][x + 1] = 7 if check[y + 1][x - 1] == check[y][x] and check[y - 1][x + 1] == check[y][x]: # 若右上與左下是相同貓咪,將右上與左下格子裡的貓變成肉球 cat[y + 1][x - 1] = 7 cat[y][x] = 7 cat[y - 1][x + 1] = 7 def game_main(): global cursor_x, cursor_y, mouse_c if 660 <= mouse_x and mouse_x < 840 and 100 <= mouse_y and mouse_y < 160 and mouse_c == 1: # 若點選氣球的 '測試' 後 mouse_c = 0 # 解除旗標 check_cat() # 呼叫判斷是否連成一線的函式 if 24 <= mouse_x and mouse_x < 24 + 72 * 8 and 24 <= mouse_y and mouse_y < 24 + 72 * 10: # 若滑鼠游標位於遊戲畫面之內 cursor_x = int((mouse_x - 24) / 72) cursor_y = int((mouse_y - 24) / 72) if mouse_c == 1: mouse_c = 0 cat[cursor_y][cursor_x] = random.randint(1, 2) cvs.delete('CURSOR') cvs.create_image(cursor_x * 72 + 60, cursor_y * 72 + 60, image = cursor, tag = 'CURSOR') cvs.delete('CAT') draw_cat() root.after(100, game_main) root = tkinter.Tk() root.title('垂直、水平、傾斜的方向是否有大於等於3個相同的貓咪') root.resizable(False, False) root.bind('', mouse_move) root.bind('', mouse_press) cvs = tkinter.Canvas(root, width = 912, height = 768) cvs.pack() bg = tkinter.PhotoImage(file = 'images/cat_bg.png') cursor = tkinter.PhotoImage(file = 'images/cat_cursor.png') img_cat = [ None, tkinter.PhotoImage(file = 'images/cat1.png'), tkinter.PhotoImage(file = 'images/cat2.png'), tkinter.PhotoImage(file = 'images/cat3.png'), tkinter.PhotoImage(file = 'images/cat4.png'), tkinter.PhotoImage(file = 'images/cat5.png'), tkinter.PhotoImage(file = 'images/cat6.png'), tkinter.PhotoImage(file= 'images/cat_paw.png') ] cvs.create_image(456, 384, image = bg) cvs.create_rectangle(660, 100, 840, 160, fill = 'white') # 在氣球內繪製方框 cvs.create_text(750, 130, text = '測試', fill = 'red', font = ('Times New Roman', 30)) # 顯示 '測試' 文字 game_main() root.mainloop() ### ex4-8 ### import tkinter import random index = 0 # 管理遊戲流程的變數 timer = 0 # 管理時間的變數 score = 0 # 管理分數的變數 next_cat = 0 # 設定下一個貓咪的變數 cursor_x = 0 cursor_y = 0 mouse_x = 0 mouse_y = 0 mouse_c = 0 def mouse_move(e): # 移動滑鼠時執行的函式 global mouse_x, mouse_y mouse_x = e.x mouse_y = e.y def mouse_press(e): # 點選滑鼠時執行的函式 global mouse_c mouse_c = 1 cat = [] check = [] for i in range(10): # 透過迴圈與 list 的 append() 初始化 list cat.append([0, 0, 0, 0, 0, 0, 0, 0]) check.append([0, 0, 0, 0, 0, 0, 0, 0]) def draw_cat(): # 顯示貓咪的函式 cvs.delete('CAT') for y in range(10): for x in range(8): if cat[y][x] > 0: cvs.create_image(x * 72 + 60, y * 72 + 60, image = img_cat[cat[y][x]], tag = 'CAT') def check_cat(): # 判斷水平、垂直、傾斜的貓咪連成一線的函式 for y in range(10): for x in range(8): check[y][x] = cat[y][x] for y in range(1, 9): for x in range(8): if check[y][x] > 0: if check[y - 1][x] == check[y][x] and check[y + 1][x] == check[y][x]: cat[y - 1][x] = 7 cat[y][x] = 7 cat[y + 1][x] = 7 for y in range(10): for x in range(1, 7): if check[y][x] > 0: if check[y][x - 1] == check[y][x] and check[y][x + 1] == check[y][x]: cat[y][x - 1] = 7 cat[y][x] = 7 cat[y][x + 1] = 7 for y in range(1, 9): for x in range(1, 7): if check[y][x] > 0: if check[y - 1][x - 1] == check[y][x] and check[y + 1][x + 1] == check[y][x]: cat[y - 1][x - 1] = 7 cat[y][x] = 7 cat[y + 1][x + 1] = 7 if check[y + 1][x - 1] == check[y][x] and check[y - 1][x + 1] == check[y][x]: cat[y + 1][x - 1] = 7 cat[y][x] = 7 cat[y - 1][x + 1] = 7 def sweep_cat(): # 消除連成一線的貓咪 (肉球) 的函式 num = 0 # 計算消除數量的變數 for y in range(10): for x in range(8): if cat[y][x] == 7: # 若格子裡面是肉球 cat[y][x] = 0 # 消除肉球 num = num + 1 # 消除的數量加 1 return num # 傳回消除的數量 def drop_cat(): # 讓貓咪落下的函式 flg = False # 判斷是否落下的旗標 (Flase 代表未落下) for y in range(8, -1, -1): for x in range(8): if cat[y][x] != 0 and cat[y + 1][x] == 0: cat[y + 1][x] = cat[y][x] cat[y][x] = 0 flg = True return flg def over_cat(): # 判斷是否已堆到最上層的函式 for x in range(8): if cat[0][x] > 0: return True return False def set_cat(): for x in range(8): cat[0][x] = random.randint(0, 6) def draw_txt(txt, x, y, siz, col, tg): fnt = ('Times New Roman', siz, 'bold') cvs.create_text(x + 2, y + 2, text = txt, fill = 'black', font = fnt, tag = tg) cvs.create_text(x, y, text = txt, fill = col, font = fnt, tag = tg) def game_main(): global index, timer, score, next_cat global cursor_x, cursor_y, mouse_c if index == 0: # 標題的標誌 draw_txt('貓咪貓咪', 312, 240, 100, 'violet', 'TITLE') draw_txt('Click to start.', 312, 560, 50, 'orange', 'TITLE') index = 1 mouse_c = 0 elif index == 1: # 標題畫面 等待遊戲開始 if mouse_c == 1: for y in range(10): for x in range(8): cat[y][x] = 0 mouse_c = 0 score = 0 next_cat = 0 cursor_x = 0 cursor_y = 0 set_cat() draw_cat() cvs.delete('TITLE') index = 2 elif index == 2: # 貓咪落下 if drop_cat() == False: index = 3 draw_cat() elif index == 3: # 是否連成一線 check_cat() draw_cat() index = 4 elif index == 4: # 消除連成一線的貓咪 sc = sweep_cat() score = score + sc * 10 if sc > 0: index = 2 else: if over_cat() == False: next_cat = random.randint(1, 6) index = 5 else: index = 6 timer = 0 draw_cat() elif index == 5: # 等待玩家滑鼠輸入 if 24 <= mouse_x and mouse_x < 24 + 72 * 8 and 24 <= mouse_y and mouse_y < 24 + 72 * 10: cursor_x = int((mouse_x - 24) / 72) cursor_y = int((mouse_y - 24) / 72) if mouse_c == 1: mouse_c = 0 set_cat() cat[cursor_y][cursor_x] = next_cat next_cat = 0 index = 2 cvs.delete('CURSOR') cvs.create_image(cursor_x * 72 + 60, cursor_y * 72 + 60, image = cursor, tag = 'CURSOR') draw_cat() elif index == 6: # 遊戲結束 timer = timer + 1 if timer == 1: draw_txt('GAME OVER', 312, 348, 60, 'red', 'OVER') if timer == 50: cvs.delete('OVER') index = 0 cvs.delete('INFO') draw_txt('SCORE ' + str(score), 160, 60, 32, 'blue', 'INFO') if next_cat > 0: cvs.create_image(752, 128, image = img_cat[next_cat], tag = 'INFO') root.after(100, game_main) root = tkinter.Tk() root.title('掉落物拼圖「貓咪貓咪」') root.resizable(False, False) root.bind('', mouse_move) root.bind('', mouse_press) cvs = tkinter.Canvas(root, width = 912, height = 768) cvs.pack() bg = tkinter.PhotoImage(file = 'images/cat_bg.png') cursor = tkinter.PhotoImage(file = 'images/cat_cursor.png') img_cat = [ None, tkinter.PhotoImage(file = 'images/cat1.png'), tkinter.PhotoImage(file = 'images/cat2.png'), tkinter.PhotoImage(file = 'images/cat3.png'), tkinter.PhotoImage(file = 'images/cat4.png'), tkinter.PhotoImage(file = 'images/cat5.png'), tkinter.PhotoImage(file = 'images/cat6.png'), tkinter.PhotoImage(file= 'images/cat_paw.png') ] cvs.create_image(456, 384, image = bg) game_main() root.mainloop()