I made a entry for rename the file. When I click the file, the entry widget is open and I want I can destroy the widget when I click outside the entry widget, and if I click inside the widget, it should be not destroyed. The code is like below.
self.root.bind("<Button-1>", self.rename_cancel)
def rename_cancel(self, event):
if self.rename_act_mpf == 1:
self.rename_entry_mpf.destroy()
self.rename_act_mpf = 0
if self.rename_act_db == 1:
self.rename_entry_db.destroy()
self.rename_act_db = 0
in this code, when I click somewhere, the entry widget is destroyed even I click the inside of the widget. How can I make the exception for this?
CodePudding user response:
event.widget
will tell you which widget was clicked on. You can compare that to your entry widget, and call destroy
if the click wasn't on the entry widget.