I am writing a text editor in Tkinter, using a TopLevel
window that includes a Text
widget. Currently, when a document/buffer contains unsaved changes, I prepend the title of the window with an asterisk as in MyDocument
-> *MyDocument
, as customary under *nix environments. For that purpose, I am using the edit_modified
method of Text
as follows:
import Tkinter as tk
class EditingWindow(tk.Toplevel):
# [...]
self.text = tk.Text(...)
# track modifications of the text:
self.text.bind("<<Modified>>", self.modified)
def modified(self, event=None):
if self.text.edit_modified():
title=self.title()
if title[0] != '*':
self.title("*" + title)
else:
title=self.title()
if title[0] == '*':
self.title(title[1:])
def save(self, event=None):
# [... saving under a filename kept in the variable self.filename ...]
self.text.edit_modified(False)
self.title(os.path.basename(self.filename))
My question is: On Mac OS X, rather than prepending the window title with an asterisk, a black dot appears in the window close button (the red circular button on the topleft corner) to signify unsaved changes. Is it possible to access this feature from Tkinter (or, more generally, from Tcl/Tk)?
Edit 2:
After initial suggestions to use applescript, Kevin Walzer came up with the solution: setting tkinter
's wm_attributes
. Above, that amounts to using
self.wm_attributes("-modified", 1) # sets black dot in toplevel's close button (mac)
and
self.wm_attributes("-modified", 0) # unsets black dot in toplevel's close button (mac)
in self.modified
.