發表文章

陳暐丞Bro Code貪吃蛇python snake game

圖片
from tkinter import * import random GAME_WIDTH = 800 GAME_HEIGHT = 800 SPEED = 500 SPACE_SIZE = 50 BODY_PARTS = 3 SNAKE_COLOR = "yellow" FOOD_COLOR = "purple" BACKGROUND_COLOR = "white" 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 = random.randint(0, (GAME_WIDTH / SPACE_SIZE)-1) * SPACE_SIZE y = random.randint(0, (GAME_HEIGHT / SPACE_SIZE) - 1) * SPACE_SIZE self.coordinates = [x, y] canvas.create_oval(x, y, x + SPACE_SIZE, y + SPACE_SIZE, fill=FOOD_COLOR, tag="food") def next_turn(snake, food): x, y = ...

陳暐丞eval=evaluate函數calculator美國男生印度女生,調色版

圖片
w3schools eval() 美國男生Bro Code from tkinter import * def button_press(num): global equation_text equation_text = equation_text + str(num) equation_label.set(equation_text) def equals(): global equation_text try: total = str(eval(equation_text)) equation_label.set(total) equation_text = total except SyntaxError: equation_label.set("syntax error") equation_text = "" except ZeroDivisionError: equation_label.set("arithmetic error") equation_text = "" def clear(): global equation_text equation_label.set("") equation_text = "" window = Tk() window.title("Calculator program") window.geometry("500x500") equation_text = "" equation_label = StringVar() label = Label(window, textvariable=equation_label, font=('consolas',20), bg="white", width=24, height=2) label.pack() ...

python視窗建構Toplevel與Tk比較

圖片
mainloop() pre from tkinter import * #從tkinter函式庫輸入所有函式,檔案'window001.py' import time #412單元延續數入time套件 def delete(): #增加自訂函數def delete() List[int(n.get())-1].destroy() #destroy破壞視窗List[索引] win.config(bg='red') b1=Label(win,text='陳暐丞',font='Arial 100 bold',bg='#0000ff').pack() x=('幹','你','娘','💩','?','\U0001F4A9') #建立元祖tuple名為x,0,1,2,3,4,5 List = [] #建立串列list名為List win=Tk() #建構子 constructor win.geometry('400x200+800+0') win.title('陳暐丞控制原來的視窗') n = StringVar(win) #類別變數 n.set('刪除') op1 = OptionMenu(win,n,1,2,3,4,5,6).pack() bu1 = Button(win,text='刪除選取視窗',command=delete,font='20',bg='blue',fg='white') bu1.pack() for i in range(6): window = Toplevel() window.title('陳暐丞第%d個視窗' % (i+1)) window.geometry('300x250+%d+%d' % (i*300,i*50)) b1=Label(window,text=x[i],font='A...

陳暐丞tkinter繪圖套件time時間sleep方法

圖片
from tkinter import * #下載程式碼,從tkinter輸入所有函式 x = ['\U0001F600','\U0001F601','\U0001F602','\U0001F603','\U0001F604']#定義一個串列 for i in range(5): window = Tk() #建構視窗,名為window建構一個房子 window.title('陳暐丞第%d視窗' % (i+1)) window.geometry('400x400+%d+%d' % (400*i, i*100)) b1=Label(window,text=x[i],font='Arial 250 bold').pack() window.mainloop()

陳暐丞期中考emoji繪文字onchange事件

圖片
陳暐丞輸入參數 輸入k 輸入m 輸入n 執行自訂函數 red green blue 重點 span手掌張開拇指到小指,短橋梁長度。 VSCode是IDE整合開發環境。 CTRL+SHIFT+L一次改全部 Integrated Development Environment alert內建函數,自訂函數abc 利用id加上syle方法是#id 老師的公民記者 https://www.peopo.org/news/672998 陳暐丞輸出結果

陳暐丞python與JAVASCRIPT程式碼對照

圖片
h1{background-color: purple; color: white; border: 10px solid red; text-align:center; padding: 5px} ul{background-color: green; color: white; font-size: 2em;line-height:1.5} input{font-size:24px;background-color:rgb(210, 250, 215);} .monkey{font-size:36px;} pre{background-color: purple; color: white;} 陳暐丞輸入參數 輸入k 輸入m 輸入n 執行自訂函數 重點 alert內建函數,自訂函數abc 陳暐丞輸出結果

陳暐丞python寫入write迴圈範圍range

圖片
space, slash, backslash, cr = ' ', '/', '\\', '\n' k = input('邊長: ') #輸入字串 m = input('橫向: ') k, m = int(k), int(m) f = open("難嗎.txt",'w',encoding='utf8') f.write('劉任昌讀取檔案' + cr)#註解\n換列 for i in range(9): f.write(str(i)) f.write(cr) for i in range(1, k+1): #迴圈1到k for ii in range(m): for j in range(k-i): f.write(space) f.write(slash) for j in range(2*i-2): f.write(space) f.write(backslash) for j in range(k-i): f.write(space) f.write(cr) for i in range(1, k+1): for ii in range(m): for j in range(i-1): f.write(space) f.write(backslash) for j in range(2*k-2*i): f.write(space) f.write(slash) for j in range(i-1): f.write(space) f.write(cr) f.close()