473,508 Members | 2,434 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Selection in Tkinter Text widget.

Ant
Hi all,

I have been trying to select text in a Text widget programmatically. I
have been trying the following minimal example:
#=================================
from Tkinter import *

def showgui():
win = Tk()

area = Text(win, width = 50, height = 20)
area.pack()

new = """Lots of text here
and here
and here..."""
area.insert("1.0", new)

area.tag_add(SEL, "1.0", END)

win.mainloop()

if __name__ == "__main__":
showgui()
#==================================

The area.tag_add(...) line should - from what I have read in Frederik's
Intro to Tkinter guide - select all of the text in the text area. It
doesn't however...

Does anyone have any idea how to get this to work? Or tell me what I am
doing wrong.

Cheers,

--
Ant...

Jun 2 '06 #1
3 11928
"Ant" <an****@gmail.com> wrote:
I have been trying to select text in a Text widget programmatically. I
have been trying the following minimal example:
#=================================
from Tkinter import *

def showgui():
win = Tk()

area = Text(win, width = 50, height = 20)
area.pack()

new = """Lots of text here
and here
and here..."""
area.insert("1.0", new)

area.tag_add(SEL, "1.0", END)
area.focus_set()
win.mainloop()

if __name__ == "__main__":
showgui()
#==================================

The area.tag_add(...) line should - from what I have read in Frederik's
Intro to Tkinter guide - select all of the text in the text area. It
doesn't however...


it does, but by default, the selection is only shown for widgets that has the key-
board focus. if you add an explicit focus_set() call, you'll see the selection.

</F>

Jun 2 '06 #2
Ant

Fredrik Lundh wrote:
....
it does, but by default, the selection is only shown for widgets that has the key-
board focus. if you add an explicit focus_set() call, you'll see the selection.

</F>


Perfect! Thanks Fredrik.

Strange behaviour though (IMHO), that the selection is only shown if
the widget has focus. I just tried adding another component to the
test, and switching from widget to widget does indeed stop the
selection showing!

Cheers,

--
Ant...

Jun 2 '06 #3
Ant wrote:
Strange behaviour though (IMHO), that the selection is only shown if
the widget has focus.


It's only strange if you're used to certain platforms.
This is normal behaviour in the Macintosh world. One
of the original Apple UI Guidelines was that there
should only be one selection visible at a time, so
that it's always clear what you're operating on.

(They seem to be breaking that now in MacOSX, which
I think is a backward step...)

--
Greg
Jun 3 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3721
by: Srinath Avadhanula | last post by:
Hello, Sorry to be bringing up what seems to be a somewhat beaten up topic... This is what I wanted to do: Create a _simple_ text editor widget which supports VI(M) style keybindings but...
2
4129
by: Irmen de Jong | last post by:
Hi, I'm having trouble with the code below. It's just a regular Tk text widget in which you can type and select text as expected, however the call to tkFileDialog.askopenfilename() seems to screw...
1
2239
by: Pekka Niiranen | last post by:
Hi there, after reading TkInter/thread -recipe: http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/82965 I wondered if it was possible to avoid using threads for the following problem: ...
2
2929
by: Tonino | last post by:
Hi, I have a small Tkinter app that gets data from a socket connection to a "server". The app has a Text() widget to display the info that it gets from the socket connection. I have the...
0
2338
by: Stewart Midwinter | last post by:
I have a Tkinter app running on cygwin. It includes a Test menu item that does nothing more than fetch a directory listing and display it in a Toplevel window (I'd use a tkMessageBox showinfo...
2
8191
by: rahulnag22 | last post by:
Hi, I guess this is a very trivial question -- I am using a label widget to display text (black font in a white background color). I am trying to use my mouse to scroll over the displayed text to...
0
1821
by: lee.walczak | last post by:
I actually post a topic relating to my problem here: (http://groups.google.co.uk/group/comp.lang.python/browse_thread/ thread/a073d532c4481bfe?hl=en# ) But I thought it could be useful to...
3
3900
by: J-Burns | last post by:
Hello. Im a bit new to using Tkinter and im not a real pro in programming itself... :P. Need some help here. Problem 1: How do I make something appear on 2 separate windows using Tkinter? By...
4
5553
by: Mudcat | last post by:
I've tried quite a few things to get this correct but have hit a couple of sticking points that I can't figure out. I need to ge the Text box to function like the 'wraplength' option in a Label. ...
0
7323
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,...
1
7038
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...
0
7493
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...
1
5049
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4706
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...
0
3180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1550
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
763
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
415
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...

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.