467,879 Members | 1,202 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 467,879 developers. It's quick & easy.

tkinter text editor

I'm writing text editor.

How to enable/disable (cut, copy etc.) when text is selected/not selected
Mar 8 '07 #1
  • viewed: 3259
Share:
6 Replies
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
Mar 8 '07 #2
On Friday 09 March 2007 12:04, Gigs_ wrote:
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
Mar 8 '07 #3
jim-on-linux wrote:
On Friday 09 March 2007 12:04, Gigs_ wrote:
>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
Mar 8 '07 #4
Gigs_ wrote:
jim-on-linux wrote:
>On Friday 09 March 2007 12:04, Gigs_ wrote:
>>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.

James
Mar 8 '07 #5
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()
Mar 9 '07 #6

---------- Original Message -----------
From: Gigs <gi**@hi.t-com.hr>
To: John McMonagle <jm********@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/tk...41-methods.htm
Mar 10 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Jane Austine | last post: by
5 posts views Thread by max(01)* | last post: by
4 posts views Thread by phil | last post: by
6 posts views Thread by Richard Lewis | last post: by
2 posts views Thread by import newbie | last post: by
1 post views Thread by Michael Yanowitz | last post: by
1 post views Thread by Gigs_ | last post: by
1 post views Thread by Gigs_ | last post: by
reply views Thread by MrMoon | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.