發表文章

朱冠宇keyevent期末考

圖片
from tkinter import * def doSomething(event): #print("You pressed: " + event.keysym) label.config(text=event.keysym) window = Tk() window.title('朱冠宇期末考') window.bind("&ltKey&gt",doSomething) label = Label(window,font=("Helvetica",300),bg='yellow') label.pack() window.mainloop()

朱冠宇Bro Code貪吃蛇python snake game

圖片
from tkinter import * import random GAME_WIDTH = 1000 GAME_HEIGHT = 700 SPEED = 500 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 , ( GA...

朱冠宇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") 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() frame = Frame(w...

朱冠宇tkinter繪圖套件time時間sleep方法

圖片
程式碼 from tkinter import * #下載程式碼,從tkinter輸入所有函式 import time x = [ ' \U0001F600 ' , ' \U0001F601 ' , ' \U0001F602 ' , ' \U0001F615 ' , ' \U0001F622 ' ] #定義一個串列 y = [] #追蹤特定視窗用途,尚未使用 for i in range ( 5 ):     window = Tk () #建構視窗,名為window建構一個房子     window . title ( '朱冠宇python第 %d 視窗' % ( i + 1 ))     window . geometry ( '400x400+ %d +100' % ( 400 * i ))     b1 = Label ( window , text = x [ i ], font = 'Arial 250 bold' ). pack ()     time . sleep ( 1 )     window . update ()     y . append ( window ) #追蹤特定視窗用途,尚未使用 window . mainloop ()

朱冠宇python期中考javascript按鈕button事件onchange

圖片
js程式碼 const space = ' ' , slash = '/' , backslash = ' \\ ' , cr = ' \n ' ; function row1 ( k , m ){     for ( let i = 0 ; i < k ; i ++ ){         for ( let ii = 0 ; ii < m ; ii ++ ){             for ( let j = 0 ; j < k - i - 1 ; j ++ )                 out += space ;             out += slash ;             for ( let j = 0 ; j < 2 * i ; j ++ )                 out += space ;             out += backslash ;             for ( let j = 0 ; j < k - i - 1 ; j ++ )                 out += space ;};     out += cr ;};}; function row2 ( k , m ){     for ( let i = 0 ; i < k ; i ++ ){         for ( let ii = 0 ; ii < m ; ii ++ ){  ...

朱冠宇Python與javascript程式碼對照

圖片
朱冠宇輸入參數 輸入k 輸入m 輸入n 執行自訂函數 重點 alert內建函數,自訂函數abc 朱冠宇輸出結果

朱冠宇Python自訂函數迴圈write模式a與w

圖片
上面的程式碼 <style>   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} </style> VS code截圖 程式碼 a space, slash, backslash, cr = ' ', '/', '\\', '\n' def row1(k,m):#定義自訂函數 for i in range(1, k+1): 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) def row2(r,m): 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)...