{Possible_Spam} Re: {Possible_Spam} tkinter text editor
John McMonagle
johnmc at velseis.com.au
Fri Mar 9 18:53:03 EST 2007
---------- Original Message -----------
From: Gigs <gigs at hi.t-com.hr>
To: John McMonagle <jmcmonagle at velseis.com.au>
Sent: Sat, 10 Mar 2007 15:13:20 +0100
Subject: {Possible_Spam} Re: {Possible_Spam} tkinter text editor
> John McMonagle wrote:
> > Gigs_ wrote:
> >> I'm writing text editor.
> >>
> >> How to enable/disable (cut, copy etc.) when text is selected/not
> >> selected
> >
> >
> > Bind the Button1-ButtonRelease event to a function which checks the
> > length of the SEL tag of the text widget. If it is zero length,
> > disable the appropriate menu entries, if it is non-zero, enable the
> > appropriate menu entries.
> >
> > Simple example:
> >
> >
> > from Tkinter import *
> > root = Tk()
> >
> > textWidget = Text(root)
> > textWidget.pack()
> >
> > def onButton1Release(event):
> > if len(textWidget.tag_ranges(SEL)) == 0:
> > print 'No text selected. Disable appropriate menu entries'
> > else:
> > print 'Some text selected. Enable appropriate menu entries'
> >
> > textWidget.bind('<Button1-ButtonRelease>', onButton1Release)
> >
> > root.mainloop()
> >
> thx, but what i dont know is how to change state on menu item.
> I dont know how to access that menu item later.
> I know on button like
> B = Button(root)
> B.pack()
>
> and later i change with B.config(blabla)
>
> but on menu i have more items like
> M = Menu(root)
> i.add_command(label='one', command=show1)
> i.add_command(label='two', command=show2)
> M.add_cascade(label='File', menu=i)
>
> how to change item: 'two'
>
Use the entry config method of the Menu widget:
i.entryconfig('one', state=DISABLED)
Here is some recommended reading:
http://www.pythonware.com/library/tkinter/introduction/x5841-methods.htm
More information about the Python-list
mailing list