發表文章

目前顯示的是 6月, 2024的文章

尤婕羽keyevents期末考

圖片
from tkinter import * def doSomething(event): #print("You pressed: " + event.keysym) label.config(text=event.keysym) window = Tk() window.title('尤婕羽期末考') window.bind("<Key>",doSomething) #<, >在網頁表示要使用\<, \> label = Label(window,font=("Helvetica",300)) label.pack() window.mainloop()

尤婕羽bro code貪吃蛇import module教育學習網

  https://steam.oxxostudio.tw/category/python/basic/import.html 匯入模組 import Module 在 Python 裡,「模組」是一個存在於任意程式碼中的檔案,任何 Python 的程式碼也都可以當作模組使用,透過 import 陳述式,可以引用其他模組的程式碼,進一步使用其他模組的程式和變數,讓程式更精簡更好維護。 改寫自bro code貪吃蛇 from tkinter import * import random #亂數模組 GAME_WIDTH , GAME_HEIGHT = 1000 , 800 SPEED = 200 #時間單位是千分之一秒 SPACE_SIZE , BODY_PARTS = 50 , 3 #左邊變數 assigning value SNAKE_COLOR = "green" FOOD_COLOR = [ 'pink' , 'yellow' , 'orange' , 'tomato' ] #改成串列可以選擇 BACKGROUND_COLOR = "black" class Snake :     def __init__ ( self ):         self . body_size = BODY_PARTS         self . coordinates = []         self . squares = []         for i in range ( 0 , BODY_PARTS ):             self . coordinates . append ([ 0 , 0 ])         for x , y in self . coordinates :             square = canvas . create_...

尤婕羽bro code貪吃蛇

圖片
程式碼貼上要用撰寫模式 from tkinter import * import random GAME_WIDTH , GAME_HEIGHT = 1000 , 800 SPEED = 1000 SPACE_SIZE , BODY_PARTS = 50 , 3 #左邊變數 assigning value SNAKE_COLOR = "#00FF00" FOOD_COLOR = "white" BACKGROUND_COLOR = "#000000" class Snake :     def __init__ ( self ):         self . body_size = BODY_PARTS         self . coordinates = []         self . squares = []         for i in range ( 0 , BODY_PARTS ):             self . coordinates . append ([ 0 , 0 ])         for x , y in self . coordinates :             square = canvas . create_rectangle ( x , y , x + SPACE_SIZE , y + SPACE_SIZE , fill = SNAKE_COLOR , tag = "snake" )             self . squares . append ( square ) class Food :     def __init__ ( self ):         x = ...