Tkinter Menu Item Activation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • MartinRinehart@gmail.com

    Tkinter Menu Item Activation

    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.

  • Rob Wolfe

    #2
    Re: Tkinter Menu Item Activation

    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.entryconf igure(2, state=state)

    root = Tk.Tk()
    menubar = Tk.Menu(root)
    mfile = Tk.Menu(menubar )
    mfile.add_comma nd(label="Open" , command=hello)
    mfile.add_comma nd(label="Save" , command=hello)
    menubar.add_cas cade(label='Fil e', menu=mfile)
    root.config(men u=menubar)
    root.mainloop()
    </code>

    But I think that you should read this:


    HTH,
    Rob

    Comment

    • MartinRinehart@gmail.com

      #3
      Re: Tkinter Menu Item Activation



      Rob Wolfe wrote:
      But I think that you should read this:
      http://effbot.org/zone/vroom.htm
      Rob, may the gods shower you with gold coins!

      Comment

      • Eric Brunel

        #4
        Re: Tkinter Menu Item Activation

        On Fri, 22 Feb 2008 13:30:06 +0100, <MartinRinehart @gmail.comwrote :
        [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 (>= 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(F alse).

        HTH
        --
        python -c "print ''.join([chr(154 - ord(c)) for c in
        'U(17zX(%,5.zmz 5(17l8(%,5.Z*(9 3-965$l7+-'])"

        Comment

        Working...