Tkinter Menu Item Activation

M

MartinRinehart

Tkinter definitely deserves more respect! I'm making rapid progress
and it looks good.

But am stuck on this: I want the File/Save state to change from
disabled to enabled, depending on whether or not there is something to
save (Text modified). Google returns results in every language except
Python.

Sub problems: how to change state of menu item? how to detect changes
in Text widget?

Help appreciated.
 
R

Rob Wolfe

Tkinter definitely deserves more respect! I'm making rapid progress
and it looks good.

But am stuck on this: I want the File/Save state to change from
disabled to enabled, depending on whether or not there is something to
save (Text modified). Google returns results in every language except
Python.
Sub problems: how to change state of menu item? how to detect changes
in Text widget?

Help appreciated.

State of menu items can be changed like this:

<code>
import Tkinter as Tk

def hello():
if mfile.entrycget(2, 'state') == 'disabled':
state = 'normal'
else:
state = 'disabled'
mfile.entryconfigure(2, state=state)

root = Tk.Tk()
menubar = Tk.Menu(root)
mfile = Tk.Menu(menubar)
mfile.add_command(label="Open", command=hello)
mfile.add_command(label="Save", command=hello)
menubar.add_cascade(label='File', menu=mfile)
root.config(menu=menubar)
root.mainloop()
</code>

But I think that you should read this:
http://effbot.org/zone/vroom.htm

HTH,
Rob
 
E

Eric Brunel

Sub problems: how to change state of menu item? how to detect changes
in Text widget?

If you have a reasonably recent tcl/tk version (>= 8.4), you should have a
edit_modified() method on your Text telling you if it has been modified
since you last called edit_modified(False).

HTH
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top