python:窗口化和制作圖形


#
from tkinter import * canvas = Canvas(width=800, height=600, bg='yellow')#聲明窗口屬性
canvas.pack(expand=YES, fill=BOTH) k = 1 j = 1
for i in range(0, 26): canvas.create_oval(310 - k, 250 - k, 310 + k, 250 + k, width=1)#畫圓
    k += j j += 1 mainloop()#執行整個函數

執行結果:

#直線
from tkinter import * canvas =Canvas(width=300,height=300,bg='white')#聲明窗口屬性
canvas.pack(expand=YES,fill=BOTH)#執行窗口屬性
x0 = 260#聲明坐標
y0 = 260 y1 = 90
for i in range(10): canvas.create_line(x0,y0,x0,y1, width=1, fill='red')#畫直線
        x0 = x0 - 5 y0 = y0 - 5 y1 = y1 + 5 mainloop()#執行整個函數

執行結果:

#矩形
from tkinter import * canvas =Canvas(width=300,height=300,bg='white')#聲明窗口屬性
canvas.pack(expand=YES,fill=BOTH)#執行窗口屬性
x0 = 263 y0 = 263 y1 = 275 x1 = 275
for i in range(19): canvas.create_rectangle(x0, y0, x1, y1) x0 -= 5 y0 -= 5 x1 += 5 y1 += 5 mainloop()

執行結果:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM