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

执行结果:

猜你喜欢

转载自www.cnblogs.com/dxxblog/p/9008064.html
今日推荐