[Tutor] curses.textpad.Textbox.gather()
Alan Gauld
alan.gauld at yahoo.co.uk
Mon Nov 22 05:14:59 EST 2021
On 22/11/2021 03:40, Alex Kleider wrote:
> """
> I expect this will be of interest only to those using the curses
> module.
>
> I found that the Textbox.gather method seems incapable of returning
> a string without a trailing space.
So it seems although I'd not noticed until,your post...
> but I'm wondering if there's a better way. Specifically to provide the
> user with the option of having or not having a trailing space.
As you say its easy to remove the spaces with rstrip()
And its equally easy to add a space if needed.
So you could write a wrapper that took a space parameter and
added/removed spaces as needed.
> # create the text box with border around the outside
> tb_border = cur.newwin(3,52,y+1,x)
> tb_border.box()
> tb_border.refresh()
> tb_body = cur.newwin(1,50,y+2,x+1)
> tb = Textbox(tb_body)
> for ch in text: # insert starting text
> tb.do_command(ch)
> tb.edit() # start the editor running, Ctrl-G ends
> s2 = tb.gather() # fetch the contents
Hmm, this all feels oddly familiar.... :-)
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list