tk8_canvas.py 871 B

1234567891011121314151617181920212223242526272829
  1. # View more python learning tutorial on my Youtube and Youku channel!!!
  2. # Youtube video tutorial: https://www.youtube.com/channel/UCdyjiB5H8Pu7aDTNVXTTpcg
  3. # Youku video tutorial: http://i.youku.com/pythontutorial
  4. import tkinter as tk
  5. window = tk.Tk()
  6. window.title('my window')
  7. window.geometry('200x200')
  8. canvas = tk.Canvas(window, bg='blue', height=100, width=200)
  9. image_file = tk.PhotoImage(file='ins.gif')
  10. image = canvas.create_image(10, 10, anchor='nw', image=image_file)
  11. x0, y0, x1, y1= 50, 50, 80, 80
  12. line = canvas.create_line(x0, y0, x1, y1)
  13. oval = canvas.create_oval(x0, y0, x1, y1, fill='red')
  14. arc = canvas.create_arc(x0+30, y0+30, x1+30, y1+30, start=0, extent=180)
  15. rect = canvas.create_rectangle(100, 30, 100+20, 30+20)
  16. canvas.pack()
  17. def moveit():
  18. canvas.move(rect, 0, 2)
  19. b = tk.Button(window, text='move', command=moveit).pack()
  20. window.mainloop()