Advertisement
here2share

# tk_obj_add_tag_and_delete_tag.py

Sep 19th, 2022
2,217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.52 KB | None | 0 0
  1. # tk_obj_add_tag_and_delete_tag.py
  2.  
  3. from tkinter import *
  4.  
  5. root = Tk()
  6. root.geometry("300x100")
  7. root.title("tk Tagging" )
  8. canvas = Canvas(root)
  9. p_tag = canvas.create_oval(10, 10, 50, 50, fill="green")
  10. canvas.pack()
  11.  
  12. # add tag "yes"
  13. canvas.addtag("yes", 'withtag', p_tag)
  14.  
  15. # add tag "no"
  16. canvas.addtag("no", 'withtag', p_tag)
  17.  
  18. # print all tags from p_tag
  19. print(canvas.gettags(p_tag))
  20.  
  21. # delete tag "no"
  22. canvas.dtag(p_tag, "no")
  23.  
  24. # print all tags from p_tag
  25. print(canvas.gettags(p_tag))
  26.  
  27. root.mainloop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement