Tkinter: check for changes

I am new to python / tkinter programmer! I am showing a text widget that the user can use as a barebone editor.

Is it possible to check if the user has changed in any way so that I know if he needs the savefile step?

thank!

Alessandro

+5
source share
1 answer

The easiest way would be to use the method Text.edit_modified(). A simple use case:

>>> import Tkinter
>>> root = Tkinter.Tk()
>>> frame = Tkinter.Frame(root)
>>> text = Tkinter.Text(frame)
>>> text.pack()
>>> frame.pack()
>>> text.edit_modified()
0
>>> text.insert('1.0', 'some text')
>>> text.edit_modified()
1
>>> text.edit_modified(False)
''
>>> text.edit_modified()
0
+7
source

All Articles