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

David Mallwitz dmallwitz at cox.rr.com
Wed Dec 19 18:47:43 EST 2001


"Steve Holden" <sholden at holdenweb.com> wrote in message
news:CC1U7.38101$PA.32115 at atlpnn01.usenetserver.com...
> "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/
>
>
>
>
>
Whoops. Guess I could have been a little clearer in my original post...

    I'm processing input from a Cisco router that is directly connected to
my serial port. The router has a command line interface that will send a
'--More--' prompt when the text output is longer than the configured
terminal display length. When the user hits <space> the router will send a
series of 8 backspace characters to delete the '--More--' prompt and then
send the next page of text. Works great on a console, which is all it was
designed for. I had hoped that the Text widget would be able to interpret
the backspace character ('\b', or its' hex value '\x08') properly or that I
could configure it to do so. From the responses I have received it appears
that this is wishful thinking on my part. I'll put some more effort into
processing the router output through a regexp before I send it to the
widget.

Thanks to all,
Dave

pretty good networking guy
not so hot programmer




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