第9章 图形与图像——笔记十四

    科技2024-06-27  84

    #第9章 图形与图像 #图形与图像实验 实验9.1 图形实验 #颜色和粗细可以自行定义 #(1)绘制直线 from tkinter import * rt=Tk() rt.title('实验9.1') scnx=rt.winfo_screenwidth() scny=rt.winfo_screenheight() tm='%dx%d+%d+%d'%(500,500,(scnx-500)/2,(scny-500)/2) rt.geometry(tm) lb=Label(rt,text='绘制直线',width=30,height=2) lb.place(x=125,y=10) cv=Canvas(rt,bg='#FFFFFF',width=400,heigh=400) x1=0 y1=50 x2=400 y2=100 cv.create_line(x1,y1,x2,y2,fill='#7093DB',width=2) cv.create_line(x1,y1*2,x2,y2*2,fill='#FF7F00',width=3,arrow='first',arrowshape=(20,20,10)) cv.create_line(x1,y1*3,x2,y2*3,fill='#527F76',width=4,arrow='last',arrowshape=(20,20,10)) cv.create_line(x1,y1*4,x2,y2*4,fill='#00009C',width=6,arrow='both',arrowshape=(20,20,20)) cv.place(x=50,y=50) rt.mainloop() #(2)绘制圆弧 '''from tkinter import * rt=Tk() rt.title('实验9.1') scnx=rt.winfo_screenwidth() scny=rt.winfo_screenheight() tm='%dx%d+%d+%d'%(500,500,(scnx-500)/2,(scny-500)/2) rt.geometry(tm) lb=Label(rt,text='绘制圆弧',width=30,height=2) lb.place(x=125,y=10) cv=Canvas(rt,bg='#FFFFFF',width=400,heigh=400) cv.create_arc((10,10,100,100),start=0,extent=90,style=PIESLICE) cv.create_arc((50,50,300,300),start=0,extent=90,style=CHORD) cv.create_arc((200,200,300,300),start=0,extent=90,style=ARC) cv.place(x=50,y=50) rt.mainloop()''' #(4)绘制图形 '''from tkinter import * rt=Tk() rt.title('实验9.1') scnx=rt.winfo_screenwidth() scny=rt.winfo_screenheight() tm='%dx%d+%d+%d'%(500,500,(scnx-500)/2,(scny-500)/2) rt.geometry(tm) lb=Label(rt,text='绘制图形',width=30,height=2) lb.place(x=125,y=10) cv=Canvas(rt,bg='#FFFFFF',width=400,heigh=400) cv.create_line(20,20,20,400,fill='#00FFFF',width=3) cv.create_line(80,80,80,400,fill='#5C3317',width=3,dash=(30,10),arrow='last',arrowshape='20 20 10') cv.create_polygon([120,120,180,120,180,180,120,180],outline='#7093DB',width=3,fill='#70DB93') cv.create_oval((180,200,280,300),outline='#000000',fill='#32CD99') cv.create_oval((280,10,340,310),outline='#215E21') cv.place(x=50,y=50) rt.mainloop()'''
    Processed: 0.009, SQL: 8