1. 程式人生 > >python-GUI

python-GUI

pytho canvas das height ash eat font gray mman

tkinter:是python跨平臺的自帶庫。

 1 import random
 2 from tkinter import *
 3 # 構建一個窗口
 4 tk=Tk()
 5 tk.title("GUI")
 6 def wwh():
 7     print("想學習找我,嘿嘿")
 8 
 9 # 構建一個畫布,寬高,以像素為單位
10 canvas=Canvas(tk,width=200,height=100)
11 canvas.pack()
12 btn=Button(tk,text="這是一個rb網站....你敢嗎?",command=wwh)
13 # 顯示界面
14 btn.pack()
15 16 canvas.create_rectangle(10,10,50,50) 17 canvas.create_line(10,10,200,200) 18 canvas.create_rectangle(20,20,100,50) 19 canvas.create_arc(75,75,175,100,extent=359,style=ARC) 20 canvas.create_polygon(100,20,175,50,120,80,150,90) 21 22 def random_wwh(width,height): 23 x=random.randrange(width) 24 y=random.randrange(height)
25 x1=x+random.randrange(width) 26 y1=y+random.randrange(height) 27 canvas.create_rectangle(x,y,x1,y1,stipple=gray12,dash=10) 28 29 # 循環繪制200個圖形 30 for wwh in range(0,200): 31 random_wwh(300,300) 32 33 # 運行 34 tk.mainloop()

python-GUI