Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Okay, after <strike>tkint</strike> tinkering around a bit, I was able to figure out a working solution. I think the problem is that tags are probably not subclassed from BaseWidget.</p> <p><strong>My workaround:</strong></p> <ul> <li>Make a seperate callback for the tags; set a variable there which keeps track of which tag was clicked</li> <li>Let the event handler of the text widget decide what to do depending on the content of this variable</li> </ul> <p>The workaround in code (sorry for using <code>global</code> here, but I just modified my questions simple example...):</p> <pre><code>#!/usr/bin/env python try: from Tkinter import * from tkMessageBox import showinfo except ImportError: from tkinter import * from tkinter.messagebox import showinfo tag_to_handle = '' def on_click(event, widget_origin='?'): global tag_to_handle if tag_to_handle: showinfo('Click', '"{}" clicked'.format(tag_to_handle)) tag_to_handle = '' else: showinfo('Click', '"{} " clicked'.format(widget_origin)) def on_tag_click(event, tag): global tag_to_handle tag_to_handle = tag root = Tk() text = Text(root) text.pack() text.insert(CURRENT, 'Some untagged text...\n') text.bind('&lt;Button-1&gt;', lambda e, w='textwidget': on_click(e, w)) for i in range(5): tag_name = 'tag_{}'.format(i) text.tag_config(tag_name) text.tag_bind(tag_name, '&lt;Button-1&gt;', lambda e, w=tag_name: on_tag_click(e, w)) text.insert(CURRENT, tag_name + ' ', tag_name) root.mainloop() </code></pre> <p>I hope this is helpful for people having the same problem.</p> <p>I'm still open to nicer solutions of course!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload