發表文章

李其學的 keyboard events期末考

圖片
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),bg='blue') label.pack() window.mainloop()

李其學[串列list](元組tuple){集合set}{字典:dict}

圖片
截圖 在撰寫模式貼上程式碼 from tkinter import * import random GAME_WIDTH , GAME_HEIGHT = 1000 , 800 SPEED = 200     #時間單位千分之一 SPACE_SIZE , BODY_PARTS = 50 , 3 #左邊變數 assigning value一次改全部 ctrl shift L COLOR = [ "red" , "orange" , "yellow" , "green" , "blue" , "indigo" , "purple" , "pink" ] #0123456 FOOD_COLOR = "white" BACKGROUND_COLOR = "black" class Snake : #類別Snake類別1 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 ) #產生整數亂數0到6             square = canvas . create_rectangle ( x , y , x + SPACE_SI...

李其學bro code貪吃蛇import module教育學習網

圖片
https://steam.oxxostudio.tw/category/python/basic/import.html 匯入模組 import Module 在 Python 裡,「模組」是一個存在於任意程式碼中的檔案,任何 Python 的程式碼也都可以當作模組使用,透過 import 陳述式,可以引用其他模組的程式碼,進一步使用其他模組的程式和變數,讓程式更精簡更好維護。 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_C...

李其學Lambda匿名函式google colaboratory

圖片
  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) google機器學習實驗 https://colab.research.google.com/ 教學影片 張量Tensor計算

李其學視窗物件控制連續的視窗物件

圖片
程式碼 from tkinter import * #從tkinter函式庫輸入所有函式,檔案'window001.py' import time           #412單元延續數入time套件 def delete ():         #增加自訂函數def delete()     List [ int ( n . get ()) - 1 ].destroy() #destroy破壞視窗List[索引]     window . config ( bg = '#10ff10' )     b1 = Label ( window , text = '李其學' , font = 'Arial 100 bold' , bg = '#10ff10' ). pack () x = ( '龍' , '龓' , '龕' , '💩' , ' \U0001F600 ' , ' \U0001F4A9 ' ) #建立元祖tuple名為x,0,1,2,3,4,5 List = []                   #建立串列list名為List for i in range ( 6 ):     window = Tk ()     window . title ( '李其學第 %d 個視窗' % ( i + 1 ))     window . geometry ( '300x300+ %d + %d ' % ( i * 300 , i * 100 ))     b1 = Label ( window , text = x [ i ], font = 'Arial 200 bold' ). pack ()     window . update ()     time . sleep ( 0.1 )     List . append ( window ) #新增...