美文网首页
Python 练习实例58

Python 练习实例58

作者: loinue | 来源:发表于2022-05-11 07:44 被阅读0次

来自菜鸟教程
https://www.runoob.com/python/python-exercise-example58.html
题目:画图,学用rectangle画方形。

程序分析:

rectangle(int left, int top, int right, int bottom)
参数说明:(left ,top )为矩形的左上坐标,(right,bottom)为矩形的右下坐标,两者可确定一个矩形的大小

实例(Python 2.0+)

#!/usr/bin/python
# -*- coding: UTF-8 -*-
 
if __name__ == '__main__':
    from Tkinter import *
    root = Tk()
    root.title('Canvas')
    canvas = Canvas(root,width = 400,height = 400,bg = 'yellow')
    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
        
    canvas.pack()
    root.mainloop()

现在是画方形,不知道下次画啥

相关文章

网友评论

      本文标题:Python 练习实例58

      本文链接:https://www.haomeiwen.com/subject/ppzmyrtx.html