473,769 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Tkinter and Text() widget interactivity ?

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 ability to stop the text at any
point.

What I want to be able todo is select a line from the Text() window and
double click or whatever on it to open a new window with that selected
text as a paramater to the new window.

The app is a network sniffer and I want to be able to select a line
from the Text() window and run a decode on the data from the sniffer.

any help and pointers would help. I have no idea of what to search for
;)

Thanks

Jul 18 '05 #1
2 2951
Tonino a écrit :
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 ability to stop the text at any
point.

What I want to be able todo is select a line from the Text() window and
double click or whatever on it to open a new window with that selected
text as a paramater to the new window.

The app is a network sniffer and I want to be able to select a line
from the Text() window and run a decode on the data from the sniffer.

any help and pointers would help. I have no idea of what to search for
;)

Thanks


Here is an example of what you can do :

# from Tkinter import *
#
# def action(event):
# begin,end=event .widget.tag_ran ges(SEL)
# selected_text=e vent.widget.get (begin,end)
# new_window = Toplevel(root)
# n_text = Text(new_window )
# n_text.pack()
# n_text.insert(E ND,selected_tex t)
#
# root=Tk()
# t=Text(root)
# t.pack()
# t.tag_bind(SEL, "<Button-1>",action)
# t.insert(END,"S weetness, sweetness I was only joking when I said\n")
# t.insert(END,"B y rights you should be bludgeoned in your bed")
#
# root.mainloop()

In a Text widget you can add event bindings to tags, the selected text
has the built-in tag SEL. I don't think you can bind the event
<Double-Button> to it because double-clicking on a text widget selects
the word the cursor is on ; here I use <Button-1> (left click) but you
can use other events

In the function "action" the widget where the event occured is
event.widget (the Text widget). Its method tag_ranges returns the
beginning and end of the text with the specified tag (here SEL), then
you get the selected text by the method get() of the text widget

This is explained in "An introduction to Tkinter" by Fredrik Lundh, in
the chapter "The Text Widget"
http://www.pythonware.com/library/tkinter/introduction/

Regards,
Pierre
Jul 18 '05 #2
Many thanks for this - will give it a bash ;)

Tonino

Jul 18 '05 #3

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

Similar topics

1
2253
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: I have script started from W2K console that normally prints ascii messages to the screen. However, I have command line "debug" -flag that might cause printing
7
4539
by: Harlin Seritt | last post by:
I was looking at the Tcl/Tk sourceforge page and found that there were a couple of new widgets being produced for Tcl 8.5. Does anyone know if there are any Tkinter wrappers somewhere? thanks, Harlin
2
5101
by: Grooooops | last post by:
I've been hacking around this for a few days and have gotten close to what I want... but not quite... The TKinter Docs provide this example: # configure text tag text.tag_config("a", foreground="blue", underline=1) text.tag_bind("a", "<Enter>", show_hand_cursor) text.tag_bind("a", "<Leave>", show_arrow_cursor) text.tag_bind("a", "<Button-1>", click) text.config(cursor="arrow")
8
12027
by: Dustan | last post by:
I'm trying to get a scrollbar bound with a Frame, and I keep on getting a scrollbar, but it doesn't actually scroll. Some help, please?
0
2359
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 widget, but for some reason the text is invisible on cygwin). After I close the Toplevel widget, all of the menus in my app behave as though they have no contents to them, i..e I can press on the File menu button, and see it depress, but the Exit...
1
2362
by: vijayca | last post by:
my python installation is:Active python 2.5.1 i am using Red Hat Linux i have the Tkinter module installed but any simple script produces an error.... script: from Tkinter import Label widget = Label(None, text='Hello GUI world!') widget.pack() widget.mainloop()
0
1834
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 place an example of my problem here aswell. This a small piece of testcode that creates a TableList. When the cell is selected, a ComboBox Widget is used temporarily during the editing phase. It is during this ( EditStartCmd call) that I wish to...
3
3918
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 this I mean that the format would be something like this: You have Page1 : This has 2-3 buttons on it. Clicking on each button opens up a new window respectively having
4
5600
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. I've been able to adjust the height of the text by calculating the number of lines needed to display the text. That's fairly simple. I know the number of characters in the text and width of the box (which is static). From that point I can...
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,...
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
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
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?
1
3959
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 we have to send another system
2
3562
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.