开发者

tkinter: check modified

开发者 https://www.devze.com 2023-03-16 11:15 出处:网络
I\'m a newbie python/tkinter programmer! I am displaying a text widget for the user to use as a barebones editor.

I'm a newbie python/tkinter programmer! I am displaying a text widget for the user to use as a barebones editor.

Is it possible to check if the user modified it in any way, so that I know if it necessary a savef开发者_开发百科ile step?

thanks!

alessandro


The easiest thing to do would be to use the Text.edit_modified() method. A simple usage example:

>>> 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
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号