当前位置:   article > 正文

python菜鸟教程-画矩形_python tkinter画矩形

python tkinter画矩形

58画图,学用rectangle画方形

  1. from tkinter import *
  2. root = Tk()
  3. root.title('Canvas')
  4. canvas = Canvas(root,width = 400,height = 400, bg = 'yellow')
  5. x0 = 263
  6. y0 = 263
  7. y1 = 275
  8. x1 = 275
  9. for i in range(19):
  10. canvas.create_rectangle(x0,y0,x1,y1)
  11. x0 -= 5
  12. y0 -= 5
  13. x1 += 5
  14. y1 += 5
  15. canvas.pack()
  16. root.mainloop()

从里到外画图的,x0 =y0 ,x1 = y1。

  1. #!/usr/bin/python
  2. # -*- coding: UTF-8 -*-
  3. if __name__ == '__main__':
  4. from tkinter import *
  5. canvas = Canvas(width=300, height=300, bg='green')
  6. canvas.pack(expand=YES, fill=BOTH)
  7. x0 = 150
  8. y0 = 100
  9. canvas.create_oval(x0 - 10, y0 - 10, x0 + 10, y0 + 10)
  10. canvas.create_oval(x0 - 20, y0 - 20, x0 + 20, y0 + 20)
  11. canvas.create_oval(x0 - 50, y0 - 50, x0 + 50, y0 + 50)
  12. import math
  13. B = 0.809
  14. for i in range(16):
  15. a = 2 * math.pi / 16 * i
  16. x = math.ceil(x0 + 48 * math.cos(a))
  17. y = math.ceil(y0 + 48 * math.sin(a) * B)
  18. canvas.create_line(x0, y0, x, y, fill='red')
  19. canvas.create_oval(x0 - 60, y0 - 60, x0 + 60, y0 + 60)
  20. for k in range(501):
  21. for i in range(17):
  22. a = (2 * math.pi / 16) * i + (2 * math.pi / 180) * k
  23. x = math.ceil(x0 + 48 * math.cos(a))
  24. y = math.ceil(y0 + 48 + math.sin(a) * B)
  25. canvas.create_line(x0, y0, x, y, fill='red')
  26. for j in range(51):
  27. a = (2 * math.pi / 16) * i + (2 * math.pi / 180) * k - 1
  28. x = math.ceil(x0 + 48 * math.cos(a))
  29. y = math.ceil(y0 + 48 * math.sin(a) * B)
  30. canvas.create_line(x0, y0, x, y, fill='red')
  31. mainloop()

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/神奇cpp/article/detail/742889
推荐阅读
相关标签
  

闽ICP备14008679号