>>Gigs_ wrote:
>>>
>>>I'm writing text editor.
>>>>
>>>How to enable/disable (cut, copy etc.) when
>>>text is selected/not selected
>>>
>>Btw it is cut copy ... in edit menu
>>
>>
>>
>state = 'diabled' ## no change allowed
> ## to Text Wiget
>state = 'normal' ## default for Text Wiget
>>
>jim-on-linux
>http:\\www.inqvista.com
>
yes man but i want to make that when there is no selected text this menu
items go DISABLED and when text is selected this menu items go NORMAL
You have to methodically determine on an event by event basis what is
going to cause selection and what isn't, then update the menus
accordingly. It takes a lot of testing. An alternative is polling
whether text is selected at the moment but is a waste of CPU cycles and
is unnecessary.
Best is to let the system clipboard handle copy-paste as it was designed
to do. You are opening a can of worms trying to micromanage your
application.
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 onButton1Releas e(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'
Re: {Possible_Spam} Re: {Possible_Spam} tkinter text editor
---------- Original Message -----------
From: Gigs <gigs@hi.t-com.hr>
To: John McMonagle <jmcmonagle@vel seis.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 onButton1Releas e(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'
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(l abel='one', command=show1)
i.add_command(l abel='two', command=show2)
M.add_cascade(l abel='File', menu=i)
>
how to change item: 'two'
>
Comment