Advertisement
AyanUpadhaya

Clear everything with mouse click | Tkinter

Dec 6th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. # clear a certain part or multipart with a mouse click
  2. # for this we will use a frame
  3. # we will create a event listener and bind it to the root
  4. # anything you want to vanish from interface put inside the frame
  5. # the moment you click the mouse left button on the interface
  6. # everything visible will be vanish
  7. # ayanu881@gmail.com
  8.  
  9. from tkinter import *
  10.  
  11. root = Tk()
  12. root.title('Experiment')
  13. root.geometry('400x400')
  14.  
  15. my_frame = Frame(root)
  16.  
  17. my_label = Label(my_frame,  text="This is a text", font=('Helvetica 24  bold'))
  18. my_label.pack(pady=20)
  19.  
  20. def clear_everything(event):
  21.     my_frame.pack_forget()
  22.  
  23. my_frame.pack()
  24.  
  25. # event binding to the root
  26. root.bind('<Button-1>',clear_everything)
  27. root.mainloop()
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement