[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

Tkinter Menu Item Activation

Martin Rinehart

2/22/2008 12:30:00 PM

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.

3 Answers

Rob Wolfe

2/22/2008 6:12:00 PM

0

MartinRinehart@gmail.com writes:

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

HTH,
Rob

Martin Rinehart

2/22/2008 7:07:00 PM

0



Rob Wolfe wrote:
> But I think that you should read this:
> http://effbot.org/zone...

Rob, may the gods shower you with gold coins!

Eric Brunel

2/26/2008 9:59:00 AM

0

On Fri, 22 Feb 2008 13:30:06 +0100, <MartinRinehart@gmail.com> wrote:
[snip]
> 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 (>=3D 8.4), you should ha=
ve a =

edit_modified() method on your Text telling you if it has been modified =
=

since you last called edit_modified(False).

HTH
-- =

python -c "print ''.join([chr(154 - ord(c)) for c in =

'U(17zX(%,5.zmz5(17l8(%,5.Z*(93-965$l7+-'])"