發表文章

林佳誼類別class __init__(self, 其他參數)

圖片
w3schools類別class class Person: #定義類別class稱為Person def __init__(self, name, age): #起始屬性函數一律稱__init__ self.name = name self.age = age def myfunc(self): print("嗐,我的\n名字是" + self.name) #字串中\n換列 print("嗐,我的") print("名字是" + self.name) p1 = Person("林佳誼", 36) #利用類別建構物件(實例) p1.myfunc() 多邊形類別class 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 = [], []         fo...

林佳誼tkinter視窗套件Entry工具代替OptionMenu工具

圖片
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...

林佳誼python, input, str, float

圖片
截圖 程式碼from math import * def f(r): print(f"賴清德輸入的半徑{r} ") print(f"圓面積: {pi*r*r} ") print(f"球體積: {pi*r*r*r*4/3}") print(f"球表面積:{pi*r*r*4}") 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(sin(z))) print("餘弦cos "+str(cos(z))) def g(z): print(f"正弦sin {sin(z)}") print(f"餘弦cos {cos(z)}") def group(r, t): abc(r) tri(t) f(r) g(t) r = float(input("輸入半徑: ")) y = float(input("輸入角度360度單位: ")) t = y/180*pi #將360較度轉成弧度180=pi group(r,t)

林佳誼Python類別class函數function

圖片
截圖 程式碼 from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import *     #從函式庫 math 輸入所有 * 方法 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 * 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 ):               ...

林佳誼Python視窗GUI自訂方法canvas.delete('all')

圖片
截圖 程式碼 #原來240單元程式碼如下 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 = 160, 210, 150 #宣告圓中心座標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], width=3, fill='purple') canvas.create_line(x[k-1], y[k-1], x[0], y[0], width=3, fill='purple') #可考慮增加width寬度,fill顏色 def diagonal(): cx, cy, cr = 510, 210, 200 #宣告圓中心座標cx, cy半徑cr x, y =[],[]...

林佳誼vs code 編輯pythone圖型GUI

圖片
截圖 練習程式碼 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=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 #宣告圓中心座標cx, cy半徑cr外來學繼承 inheritance x, y =[],[] #宣告二陣列[...] k = s.get() ...

林佳誼python陣列array

圖片
w3schools截圖 w3schools程式碼 #林佳誼陣列 #for x in 'Takming gold':     # 第一个实例 #   print("當前字母: %s" % x) fruits = ['台積電', '鴻海', '聯發科'] for x in fruits:        # 第二个实例    print ("最大公司水果: %s" % x) print ("練習陣列的11個內建方法") fruits.append("中華電") #append加元素 fruits.clear() fruits = ['台積電', '鴻海', '聯發科', '中華電'] print(fruits) pig = fruits.copy() print("輸出pig=fruits.copy()結果" + str(pig)) cat = fruits print("輸出cat=fruits的結果"+str(cat)) fruits.extend(fruits) #extend尾巴+陣列, append加元素 print("extend的 "+str(fruits)) print("copy  的 "+str(pig)) print("  =   的 "+str(cat)) print(fruits.count("台積電")) fruits.insert(1,"富邦金") print(fruits) print(fruits.index("富邦金")) fruits.reverse() print(fruits) fruits.sort() print(fruits) fruits.remove("富邦金") #拿走富邦金 print(fruits) fruits.pop(2) #拿走012的2 print(fruits) #體會到只要我有耐心與興趣,我也可以當一個專業的程式開發人...