發表文章

陳映年Entry輸入文字變數textvariable字型font

圖片
VS Code截圖 VS Code程式碼 from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 import math    #從函式庫 math 輸入所有 * 方法 from time import * from random import * class Regular:     def __init__(self, cx, cy, cr, s, t, c, w): #類別共同的設定必然 def __init__ initiate發起         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 * math.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*math.cos(i*self.u))              self.y.append(self.cy + self.cr*math.sin(i*self.u))      def drawLine(self, x0, y0, x1, y1):         canvas.create_line(x0, y0, x1, y1, width = self.w, fill=self.c)     def draw(self):                                 #類別的方法         secondTime = second.get()             #取得輸入的second變數,當作區域變數secondTime         for i in range( int(self.s * 1.5) - self.t):             s

陳映年python時間函式time.sleep

圖片
VS Code截圖 VS Code程式碼 from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import *     #從函式庫 math 輸入所有 * 方法 from time import *         #取代import time class 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 =

陳映年python, input, str, float

圖片
VS code編輯環境截圖 VS code程式碼 from math import * def abc(r): print("陳映年輸入的半徑 " +str(r)) print("圓面積: "+str(pi*r*r)) print("圓周長: "+str(pi*r*2)) print("球體積: "+str(pi*r*r*r*4/3)) print("球表面積:"+str(pi*r*r*4)) def tri(z): print("陳映年輸入的角度 "+str(y)) print("正弦sin "+str(cos(z))) print("餘弦cos "+str(cos(z))) def group(r, t): abc(r) tri(t) r = float(input("輸出半徑: ") ) y = float(input("輸入角度360度單位: ") ) t = y/180*pi group(r,t) 心得 要記得做報告。

陳映年Python類別class函數function

圖片
VS Code截圖 VS Code程式碼 from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import *    #從函式庫 math 輸入所有 * 方法 class 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())     polyList.append(po

陳映年VSCode自訂方法canvas.delete('all')建構Button

圖片
微軟VS Code編輯環境與執行結果 程式碼 from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import * #從函式庫 math 輸入所有 * 方法 t = (3,4,5,6,7,8,9,10,11,12,16,20)#宣告一元組tuple(...) tk = Tk() tk.title("陳映年視窗使用者介面GUI") canvas = Canvas(tk, width=800, height=500) #建立視窗 canvas.pack() def show(event): #定義由事件event(按鈕選單)呼叫的函數show cx, cy, cr = 110, 210, 100 #宣告圓中心座標cx, cy半徑cr x, y =[],[] #宣告二陣列[...] k = s.get() #取得 ge t按鈕選單的選擇變數 u = 2 * pi / k #使用模組 math 圓周率 pi for i in range(k): x.append(cx + cr*cos(i*u)) #加入陣列的元素 y.append(cy + cr*sin(i*u)) #使用模組 math 三角函數cos, sin for i in range(k-1): canvas.create_line(x[i], y[i], x[i+1], y[i+1]) canvas.create_line(x[k-1], y[k-1], x[0], y[0] ,fill="blue",width=5) #可考慮增加width寬度,fill顏色 def diagonal(): cx, cy, cr = 410, 210, 100 #宣告圓中心座標cx, cy半徑cr x, y =[],[]

陳映年期中考VS Code編輯Python圖形使用者介面GUI

圖片
w3schools期中考截圖 微軟VS Code編輯tkinter圖形使用者介面 影片240 VS Code截圖 VS Code程式碼 #陳映年改顏色blue, purple, 元組t 增加,32 from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import * #從函式庫 math 輸入所有 * 方法 t = (3,4,5,6,7,8,9,10,11,12,16,20,32) #宣告一元組tuple(...) tk = Tk() tk.title("陳映年視窗使用者介面GUI") canvas = Canvas(tk, width=500, height=500) canvas.pack() def show(event): #定義由事件event(按鈕選單)呼叫的函數show cx, cy, cr = 210, 210, 200 #宣告圓中心座標cx, cy半徑cr x, y =[],[] #宣告二陣列[...] k = s.get() #取得 ge t按鈕選單的選擇變數 u = 2 * pi / k #使用模組 math 圓周率 pi for i in range(k): x.append(cx + cr*cos(i*u)) #加入陣列的元素 y.append(cy + cr*sin(i*u)) #使用模組 math 三角函數cos, sin for i in range(k-1): canvas.create_line(x[i], y[i], x[i+1], y[i+1]) canvas.create_line(x[k-1], y[k-1], x[0], y[0]) #可考慮增加width寬度,fill顏色 def diagonal(): cx, cy, cr = 210, 210, 200 #宣告圓中心座標c

陳映年phython陣列Array

圖片
w3schoois陣列截圖 w3schoois陣列程式碼 #陳映年拷貝自 201單元 """for x in 'Takming': #迴圈逐字元印出 print("字母: %s" % x)三引號框起註解 """ fruits = ['台積電', '鴻海', '聯發科'] #台灣市場價值最高的三公司 for x in fruits: # print ("公司: %s" % x) print(fruits) fruits.append("中華電") print("使用append") print(fruits) fruits.clear() print("使用clear") print(fruits) fruits = ['台積電', '鴻海', '聯發科', '中華電'] chicken = fruits.copy() #和 chicken = fruits 有何不同? print(chicken) fruits.append("中華電") print(fruits.count("中華電")) print(fruits.count("台積電")) for x in fruits: print(x) if x == "中華電": #判斷式是否banana print('I hate 中華電.') if x == "聯發科": #判斷式是否cherry print('I like cherry.') if x == "鴻海": #判斷式是否apple print('You are my sweet apple.') #體會到只要我有耐心與興趣,我也可以當一個專業的程式開發人員 Python有一套內建方法(built-in method