發表文章

謝宸峰期末考

圖片
from tkinter import * def doSomething(event): #print("謝宸峰按下: " + event.keysym) label.config(text=event.keysym) window = Tk() window.bind(" ",doSomething) #註解如果要在網頁放&怎麼辦理? window.title("謝宸峰期末考") #加上title label = Label(window,font=("Helvetica",100),bg='yellow') label.pack() window.mainloop() 3.Python GUI keyboard events 網址 https://www.youtube.com/watch?v=Afq9NYuwk2k from tkinter import * def doSomething(event): #print("You pressed: " + event.keysym) label.config(text=event.keysym) window = Tk() window.bind(" ",doSomething) window.title("謝宸峰期末考")#加上title label = Label(window,font=("Helvetica",200),bg='red') label.pack() window.mainloop()

謝宸峰{集合set}[串列list](元組dict和集合 )

圖片
程式碼 this= ["嗜血瘋哥", "帥哥", "小誇號", "中"] print(this) for i in range(-1,4): print(i, this[i]) w3school vsc 影片

貪吃蛇 第二集

圖片
影片 程式碼 from tkinter import * import random GAME_WIDTH , GAME_HEIGHT = 800 , 800 SPEED = 300     #時間單位千分之一 SPACE_SIZE , BODY_PARTS = 50 , 6 #左邊變數 assigning value SNAKE_COLOR = [ "Forest Green" , "Navy Blue" , "yellow" , "pink" , "Cinnamon" , "indigo" , "purple" ] FOOD_COLOR = "red" 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 :             i = random . randint ( 0 , 6 )             square = canvas . create_rectangle ( x , y , x + SPACE_SIZE , y + SPACE_SIZE , fill = SNAKE_COLOR [ i ], ta...

謝宸峰Python snake game 🐍

圖片
程式碼   from tkinter import * import random GAME_WIDTH = 1000 GAME_HEIGHT = 700 SPEED = 200 SPACE_SIZE = 50 BODY_PARTS = 3 SNAKE_COLOR = "#00FF00" FOOD_COLOR = "#FF0000" 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 = random . randint ( 0...

謝宸峰google co-laboratory 機器學習

圖片
def x ( m , n ):     #定義自訂函數x    newList = []     for i in m: #迴圈將m的元素每個都執行       newList.append(n(i))     return newList #傳回去 m=[ '王子奇' , '謝宸峰' , '劉宇寧' , '宋威龍' , '王鶴棣' ] n= lambda y: y + '是帥哥!' print (x(m,n)) for i in x(m,n):     print (i)

謝宸峰eval=evaluate函數calculator美國男生印度女生,調色盤

圖片
補充: eval=函數 Python w3chools eval() 美國男生Bro Code 印度女生

謝宸峰python視窗結構Toplevel與TK比較

圖片
程式   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 = '#1099ff' )     b1 = Label ( win , text = '謝宸峰' , font = 'Arial 100 bold' , bg = '#10ff10' ). pack () x = ( '去' , '吃' , '大' , '💩' , '💩' , ' \U0001F609 ' ) #建立元祖tuple名為x,0,1,2,3,4,5 List = []                   #建立串列list名為List win = Tk () #建構子constrctor Tk, Toplevel win . geometry ( '400x200+800+0' ) win . title ( '謝宸峰的視窗' ) n = StringVar ( win ) #類別變數 n . set ( '刪除' ) op1 = OptionMenu ( win , n , 1 , 2 , 3 , 4 , 5 , 6 ). pack ( side = LEFT ) bu1 = Button ( win , text = '刪除選取視窗' , command = delete , font = '20' , bg = 'blue' , fg = 'white' ) bu1 . pack () for i in range ( 6 ):     window = To...