proffreda

Canvas Examples

Apr 13th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. from tkinter import *
  2. master = Tk()
  3. canvas_width = 200
  4. canvas_height = 100
  5. w = Canvas(master, width=canvas_width,
  6. height=canvas_height)
  7. w.pack()
  8. y = int(canvas_height / 2)
  9. w.create_line(0, y, canvas_width, y, fill="black")
  10. w.create_rectangle(50, 20, 150, 80, fill="black")
  11. w.create_rectangle(65, 35, 135, 65, fill="yellow")
  12. w.create_line(0, 0, 50, 20, fill="red", width=3)
  13. w.create_line(0, 100, 50, 80, fill="gold", width=3)
  14. w.create_line(150,20, 200, 0, fill="green", width=3)
  15. w.create_line(150, 80, 200, 100, fill="blue", width=3)
  16.  
  17. mainloop()
  18.  
  19. ************************************************************************
  20. from tkinter import *
  21. canvas_width = 200
  22. canvas_height =200
  23. python_green = "#476042"
  24. master = Tk()
  25. w = Canvas(master,
  26. width=canvas_width,
  27. height=canvas_height)
  28. w.pack()
  29. points = [100, 140, 110, 110, 140, 100, 110, 90, 100, 60, 90, 90, 60, 100, 90, 110]
  30. w.create_polygon(points, outline=python_green,
  31. fill='yellow', width=3)
  32. mainloop()
Advertisement
Add Comment
Please, Sign In to add comment