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 savefile step?
thanks!
alessandro
We will create an event callback function by specifying the variable that stores the user input. By using the trace("mode", lambda variable, variable: callback()) method with the variable, we can trace the input on the Label widget in the window.
Running python -m tkinter from the command line should open a window demonstrating a simple Tk interface, letting you know that tkinter is properly installed on your system, and also showing what version of Tcl/Tk is installed, so you can read the Tcl/Tk documentation specific to that version.
StringVar() is a class from tkinter. It's used so that you can easily monitor changes to tkinter variables if they occur through the example code provided: def callback(*args): print "variable changed!" var = StringVar() var.trace("w", callback) var. set("hello")
Tkinter is a Python package which comes with many functions and methods that can be used to create an application. In order to create a tkinter application, we generally create an instance of tkinter frame, i.e., Tk(). It helps to display the root window and manages all the other components of the tkinter application.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With