python-GUI
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()