發表文章

目前顯示的是 5月, 2023的文章

余采珉python import openpyxl 處理EXCEL

圖片
import openpyxl #方廷煥 輸入import openpyx1處理EXCEL的函式庫 book = openpyxl.load_workbook(r'wb.xlsx') #開啟EXCEL工作簿wb.xlsx print("1. 列出所有工作表名稱") #sheetNames=book.sheetnames #所有工作表集合 #for name in sheetNames: # print(name) print("2. 針對特定工作表, 列出前面數列") #sheet = book["python"] #for row in sheet.iter_rows(min_row=1, max_row=3, min_col=1, max_col=5, values_only=True): # print(row) print("3. 列出工作表所有內容") #sheet["F1"], sheet["G1"], sheet["H1"], sheet["I1"]="波段H","波段L","部位","損益" #sheet["F2"], sheet["G2"], sheet["H2"], sheet["I2"]=sheet["C2"].value, sheet["D2"].value, 0, 0 #for row in sheet.iter_rows(min_row=1, max_row=3, min_col=1, max_col=9, values_only=True): # print(row) #book.save()

余采珉 python math random

圖片
w3schools學習python math random 貪吃蛇的python程式

余采珉python視窗使用者介面GUI類別class建構正多邊形或星形

圖片
#余采珉教python設窗程式設計 from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import * #從函式庫 math 輸入所有 * 方法 class Regular: #應一類別Regular正多邊形或星形 def __init__(self, cx, cy, cr, s, t, c, w): #類別共同的設定 self.cx, self.cy, self.cr = cx, cy, cr #取得中心座標cx, cy, 半徑cr self.s, self.t = s, t #取得邊角數目s,t尖銳程度,取代原來的k = s.get() self.c, self.w = c, w #取得顏色c,寬度w self.u = 2 * pi / self.s #使用模組 math 圓周率 pi self.x, self.y = [], [] for i in range( int(self.s * 1.5)): self.x.append(self.cx + self.cr*cos(i*self.u)) self.y.append(self.cy + self.cr*sin(i*self.u)) def draw(self): #類別的方法 for i in range( int(self.s * 1.5) - self.t): canvas.create_line(self.x[i], self.y[i], self.x[i + self.t], self.y[i + self.t], fill = self.c, width = self.w) def show(): #畫圖 poly = Regular(cx.get(), cy.get(), cr.get(), s.get(), t.get(), c.get(), w.get()) ...