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

David Mallwitz dmallwitz at cox.rr.com
Wed Dec 19 00:12:32 EST 2001


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


Best,
Dave





-----=  Posted via Newsfeeds.Com, Uncensored Usenet News  =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
 Check out our new Unlimited Server. No Download or Time Limits!
-----==  Over 80,000 Newsgroups - 19 Different Servers!  ==-----



More information about the Python-list mailing list