473,396 Members | 2,140 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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
6 3506
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Jane Austine | last post by:
As you add more items, say text lines, in Text widget, it gets too slow and almost impractical to use on. Take idle for example. If the text gets bigger(e.g. print...
5
by: max(01)* | last post by:
hello. i wrote a very simple tkinter demo program that uses menus, buttons, labels, entries, frames and secondary toplevels. it is a python version of a java program made by a colleague. ...
4
by: phil | last post by:
These work fine on Linux s.const = {} s.const = '%c' % (0xb0) s.const = '%c' % (0xf7) s.const = '%c' % (0xd8) On WinXP the symbols for division and angle work fine. But the symbol for...
6
by: Richard Lewis | last post by:
Hi there, I've got a tree control in Tkinter (using the ESRF Tree module) but I can't get it to layout how I want it. I'd like to have it so that it streches north/south (anchored to the top...
2
by: import newbie | last post by:
Hi all, I'm a programming dabbler trying learn Python, and I've got a few questions. Mainly: Where can I find a good open-source library or tutorial (preferably free) that explains how to...
1
by: Michael Yanowitz | last post by:
Hello: Below I have included a stripped down version of the GUI I am working on. It contains 2 dialog boxes - one main and one settings. It has the following problems, probably all related, that...
1
by: Gigs_ | last post by:
Can someone give me example how to write text editor in tkintter with model-view-controler? What goes to controler and what goes to model? thanks in advance
1
by: Gigs_ | last post by:
Hi I dont have idea how to write tkinter undo/redo function form my text editor and my paint program. Could someone help? I'm not asking for code, just for some guidelines to get me in the...
6
by: Juha S. | last post by:
Hi, I'm writing a small text editor type application with Python 2.5 and Tkinter. I'm using the Tk text widget for input and output, and the problem is that when I try to save its contents to a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.