Tkinter+ backspace characters (and an re.sub problem)

Steve Holden sholden at holdenweb.com
Wed Dec 19 09:34:54 EST 2001


"David Mallwitz" <dmallwitz at cox.rr.com> wrote in message
news:3c202041$1_6 at goliath.newsgroups.com...
> Hello group,
>     The Tkinter Text widget doesn't understand '\b' or '\x08' as the
> backspace character when sent a string containing either of them. Nor does
> it understand '^H' as a substitute for '\b'.
>     I've done some googling, but haven't found a solution other than doing
a
> regexp sub on the string before sending it to the text widget. That seemed
> like a good idea, but I'm not able to construct the regexp in a way that
> will handle stacked backspace characters.
>     Any ideas on how to tell the widget to process a backspace? Or on how
to
> construct an RE that will match multiple '\b's?
>
>     For example:
> >>>string = 'all work and no play makes Jack\x08\x08\x08\x08Dave a dull
boy'
> >>> print string   ###this works as you would expect it to
> all work and no play makes Dave a dull boy
> >>>root = Tk()
> >>>text = Text(root)
> >>>text.pack()
> >>>text.insert(END, string)
> ### prints 'all work and no play makes Jack||||Dave a dull boy' on the
> widget
> >>>a = re.compile('.\x08')
> >>> a.sub('', string)   ###fails - would have thought there should be 3
> '\x08's left, or none at all
> 'all work and no play makes Jac\x08Dave a dull boy'
> >>>

David:

If I understand you correctly, you are expecting the Text widget to respond
to data values in the same way as it would respond to keyboard events. This
isn't likely to happen, so you are left with having to do the preocessing
yourself.

If, on the other hand, you are saying that the backspace KEY isn't being
actioned then there would seem to be a fundamental problem with your Tkinter
installation (I know it works for me).

If the former case is what applies, where are these characters coming from?
Given that Tkinter is a GUI, why are you processing keystrokes from
elsewhere?

regards
 Steve
--
http://www.holdenweb.com/








More information about the Python-list mailing list