發表文章

D11117225 張心妮期末考

圖片
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",400),bg='yellow') 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_SIZE, y + SPACE_SIZE, fill=COLOR[i], tag="snake", width=20,outline='blue') self.squares.append(square) class Food: #類別Food 類別2 Food def __init__(self): x = random.randint(0, (GAME_WIDT...

張心妮{集合SET}[串列LIST](元組TUPLE){字典:DICT和集合一樣但key所以:冒號value值}

圖片
this=["樹","花", "草","火"] that=("元組","tuple","貓","豬","狗") print(this) for i in range(-4, 4): print(i, this[i]) for i in range(-5, 5): print(i, that[i])

張心妮bro code貪吃蛇random.randint

圖片
from tkinter import * import random GAME_WIDTH,GAME_HEIGHT = 1000, 800 SPEED = 200 #時間單位千分之一 SPACE_SIZE, BODY_PARTS= 50, 3 #左邊變數 assigning value SNAKE_COLOR = ["red","orange","yellow","green","blue","indigo", "purple"] FOOD_COLOR = "white" 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], tag="snake", width=20,outline='blue') 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 ...

張心妮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 = Fra...

張心妮tkinter繪圖套件time時間sleep方法

圖片
from tkinter import * #下載程式碼,從tkinter輸入所有函式 import time x=['\U0001F600','\U0001F609','\U0001F642','\U0001F615','\U0001F617'] for i in range(5): window = Tk() #建構視窗,名為window建構一個房子 window.title('張心妮第%d個視窗' % i) window.geometry('300x300+%d+0' % (300*i)) b1=Label(window,text=x[i],font='Arial 250 bold').pack() time.sleep(1) window.update() window.mainloop()

張心妮tkinter套件建立圖形使用者介面GUI=Graphical User Interface

圖片
from tkinter import * #下載程式碼,從tkinter輸入所有函式 window = Tk() #建構視窗,名為window建構一個房子 window.title('張心妮的python視窗') window.geometry('600x600+100+100') b1=Label(window,text='\U0001F600',font='Arial 300 bold').pack() window1 = Tk() #建構視窗,名為window建構另一個windows window1.title('張心妮的python視窗') window1.geometry('600x600+800+100')#寬x高 b1=Label(window1,text='\U0001F610',font='Arial 300 bold').pack() window.mainloop()