Reputation: 97
I am trying to make a copy of Notepad. Here, I want to get the name of the title of the tkinter window.
I need it because if the title of the window is Untitled - Notepad then I want to quit the program directly but if the title name is not Untitled - Notepad then I want to display message if you want to really quit the program.
How can I do so?
Upvotes: 3
Views: 3805
Reputation: 24038
You can just use:
if root.title() == "Untitled - Notepad":
# do something
But that might not be the best way to do it.
@tobias_k put it well:
Don't read the title of your window to determine whether the file you are currently editing is "unnamed", or has already been saved, or has been changed since the last save. Instead, keep this information in some dedicated attributes of your editor class, and use those to determine the title of the editor window. Otherwise, it will be a mess if you ever decide to change the format of the title. Also, what if the file is literally named "Untitled"?
Upvotes: 7