473,769 Members | 6,187 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 3538
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 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'

textWidget.bind ('<Button1-ButtonRelease>' , onButton1Releas e)

root.mainloop()
Mar 9 '07 #6

---------- Original Message -----------
From: Gigs <gi**@hi.t-com.hr>
To: John McMonagle <jm********@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'

textWidget.bind ('<Button1-ButtonRelease>' , onButton1Releas e)

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(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'
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
10705
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 urllib.urlopen('http://www.amazon.com').read() ), it becomes too sluggish to use as an "interactive" shell. I have tried wxPython and it seems to have the same problem (from my experience using PyCrust). Is there any way to speed up Text widget, or should I look for another
5
3008
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. the user can create ("Scrivi") a record with his second name, first name and date of birth, save ("Salva") the record to a file or read in ("Leggi") a previously created file. "Annulla" is to cancel. "Chiudi" is
4
1358
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 degrees, a little circle, produces a vertical bar in Tkinter Text box or Canvas.
6
8253
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 and bottom), is of a fixed width and is anchored to the left hand side. Here's my code (its derived from one of the examples from the ESRF web site):
2
2499
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 easily manipulate text in a tKinter window? Basically, I want to be able to do anything that HTML can do (or close to it) but without the HTML. :-)
1
3598
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 I am hoping someone knows what I am doing wrong: 1) Pressing the Settings.. Button multiple times, brings up many instances of the Settings Panel. I just want it to bring up one. Is there an easy way to do that?
1
3161
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
2966
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 right way. thanks
6
2378
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 .txt file, any Scandinavian letters such as "äöå ÄÖÅ" are saved incorrectly and show up as a mess when I open the .txt file in Windows Notepad. It seems that the characters will only get mixed if the user has typed them into the widget, but if...
0
9589
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9423
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10045
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9994
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6673
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.