|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
学了canvas,练习了一下……
0.5倍
正常尺寸
from tkinter import *
def duolamon(ratio):
root = Tk()
#获取屏幕高度
scrnh = root.winfo_screenheight()
scrnw = root.winfo_screenwidth()
r = scrnh*ratio
w = scrnw*ratio
#创建画布,大小是屏幕高度的正方形*ratio
color = 'gray' #定义背景色
canvas = Canvas(root, width=r, height=r, bg=color)
canvas.pack()
#绘制十字参考线
canvas.create_line(0, r/2, r, r/2, dash=(1,2))
canvas.create_line(r/2, 0, r/2, r, dash=(1,2))
#绘制头
canvas.create_oval(r*3/10, r*1/10, r*7/10, r*1/2, fill='blue')
canvas.create_oval(r*1/3, r*1/6, r*2/3, r*1/2, fill='white')
#绘眼睛
canvas.create_oval(r*13/30, r*2/15, r*1/2, r*1/5, fill='white')
canvas.create_oval(r*1/2, r*2/15, r*17/30, r*1/5, fill='white')
canvas.create_oval(r*57/120, r*47/300, r*59/120, r*53/300, fill='black')
canvas.create_oval(r*63/120, r*47/300, r*61/120, r*53/300, fill='black')
canvas.create_oval(r*173/360, r*49/300, r*175/360, r*51/300, fill='white')
canvas.create_oval(r*187/360, r*49/300, r*185/360, r*51/300, fill='white')
#绘鼻
canvas.create_oval(r*49/100, r*18/100, r*51/100, r*1/5, fill='red')
#绘嘴和胡须
canvas.create_line(r*1/2, r*1/5, r*1/2, r*1/3)
canvas.create_line(r*5/12, r*1/5, r*57/120, r*337/1500)
canvas.create_line(r*49/120, r*374/1500, r*57/120, r*374/1500)
canvas.create_line(r*5/12, r*448/1500, r*57/120, r*411/1500)
canvas.create_line(r*7/12, r*1/5, r*63/120, r*337/1500)
canvas.create_line(r*71/120, r*374/1500, r*63/120, r*374/1500)
canvas.create_line(r*7/12, r*448/1500, r*63/120, r*411/1500)
canvas.create_arc(r*51/120, r*448/1500, r*69/120, r*1/3, start=180, extent=180, style=ARC)
#绘身体
canvas.create_rectangle(r/3, r*12/30, r*2/3, r*21/30, outline='', fill='blue')
#绘肚子
canvas.create_oval(r*13/36, r*11/30 , r*23/36, r*58/90, outline='', fill='white')
canvas.create_arc(r*7/18, r*7/18 , r*11/18, r*11/18, start=180, extent=180, style=CHORD)
#绘项圈
canvas.create_line(r/3, r*12/30, r*2/3, r*12/30, fill='red', capstyle=ROUND, width=r/50)
canvas.create_oval(r*73/150, r*12/30, r*77/150, r*64/150, fill='yellow')
canvas.create_line(r*146/300 ,r*247/600, r*154/300, r*247/600)
canvas.create_line(r*146/300 ,r*249/600, r*154/300, r*249/600)
canvas.create_line(r/2 ,r*127/300, r/2, r*64/150)
canvas.create_oval(r*149/300, r*251/600, r*151/300, r*255/600, fill='red')
#绘手
canvas.create_polygon(r*2/9, r*9/18, r*2/9, r*10/18, r/3, r*300/600, r/3, r*249/600, fill='blue', outline='black')
canvas.create_oval(r*13/72, r*35/72, r*19/72, r*41/72, fill='white')
canvas.create_polygon(r*7/9, r*9/18, r*7/9, r*10/18, r*2/3, r*300/600, r*2/3, r*249/600,fill='blue', outline='black')
canvas.create_oval(r*59/72, r*35/72, r*53/72, r*41/72, fill='white')
#绘腿脚
canvas.create_arc(r*4/9, r*121/180, r*5/9, r*131/180, start=0, outline='', fill=color, extent=180, style=CHORD)
canvas.create_oval(r*46/150, r*121/180, r*71/150, r*131/180, fill='white')
canvas.create_oval(r*104/150, r*121/180, r*79/150, r*131/180, fill='white')
#贴标签
canvas.create_text(r*4/5, r*7/10, text='---Sun PF')
## root.mainloop()
if __name__ == '__main__':
duolamon(1)
|
|