發表文章

莊槐文tkinter視窗函式庫Entry工具widget

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

莊槐文類別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("靠!我的") print("名字是" + self.name) print("靠!我的\n名字是" + self.name) #字串中\n換列 p1 = Person("莊槐文", 36) p1.myfunc() print("印出p1.name: " + p1.name) w3schools練習class截圖 VS code練習class Stars 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*...

莊槐文python時間函式time.sleep

圖片
  from tkinter import * #從函式庫 tkinter 輸入所有 * 方法 from math import *     #從函式庫 math 輸入所有 * 方法 import time     #莊槐文輸入time函數庫,取代import time 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 .y.append( self .cy + self .cr * sin(i * self .u))     def draw ( self ):                                 #類別的方法       ...

劉任昌python自訂函數built-in內建函數import輸入函式庫

圖片
import math#莊槐文輸入math函式庫 def f(r): print("圓周率"+str(math.pi)) print("園面積"+str(math.pi*r*r)) print("圓周長"+str(math.pi*r*2)) print("球表面積"+str(math.pi*r*r*4)) print("球體積"+str(math.pi*r*r*4/3)) def g(angel): print("正弦sin "+str(math.sin(angel))) print("餘弦cos "+str(math.cos(angel))) def h(X,Y): f(X) g(Y) print("莊槐文使用數學pi, sin, cos\n") h(1,math.pi/6) #import math #莊槐文輸入math函式庫 from math import * #從數學函式庫math輸入所有函式 from tkinter import * #從tkinter視窗函式庫輸入所有函式 def f(r): #定義函數def 函數名(參數): print("圓周率"+str(pi))#字串 + str(數字) print("圓面積 "+str(pi*r*r)) print("圓周長 "+str(pi*r*2)) print("球表面積"+str(pi*r*r*4)) print("球體積 "+str(pi*r*r*4/3)) def g(angle): print("正弦sin "+str(sin(angle))) print("餘弦cos "+str(cos(angle))) def h(x,y): #最常利用在模組化 f(x) #呼叫計算面積與體積的函式 g(y) #呼叫計算三角函數的函式 print("莊槐文自訂h呼叫f,g呼叫內建函數") ...

莊槐文Python類別class函數function

圖片
  VS Code程式碼 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): #類別的方法 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(): #畫圖 define自訂函數 poly = Regular(cx.get(), cy.get(), cr.get(), s.get(), t.get(), c.get(), w.g...

w3schools字串str, format, len, slicing[::]

圖片
  w3schools Python程式碼 b = "劉德華大烏龜" #python字串單或雙引號都可 # 0 1 2 3 4 5 6 # -6-5-4-3-2-1 print("字串長度:"+str(len(b))) #相同字串型態才能串接 print("反過來:"+b[::-1]) print(b[:3]) #b字串的0,1,2 print(b[-4:-1]) print(b[-8:-4]) x = '火鍋' y = 9999 myorder = "我希望 {2} 陪我去吃 {0} 他付錢 {1}." print(myorder.format(x, y, b)) # format的參數 0, 1, 2 字串的方法列表 Method Description capitalize() Converts the first character to upper case casefold() Converts string into lower case center() Returns a centered string count() Returns the number of times a specified value occurs in a string encode() Returns an encoded version of the string endswith() Returns true if the string ends with the specified value expandtabs() Sets the tab size of the string find() Searches the string for a specified value and returns the position of where it was found format() Formats specified values in a string format_map() Formats specified values in a string index() Searches the string for a specif...