[Tutor] Arrow keys in subwindows
paulf at quillandmouse.com
paulf at quillandmouse.com
Thu Jan 12 11:17:34 EST 2023
On Thu, 12 Jan 2023 13:34:18 +0000
Alan Gauld via Tutor <tutor at python.org> wrote:
> On 12/01/2023 07:02, paulf at quillandmouse.com wrote:
> > I can't seem to get the arrow keys (KEY_LEFT, KEY_RIGHT) to work in
> > subwindows. I'm running Debian Linux with version 3.10.9 of Python.
> > When I run my code using stdscr, arrow keys work just fine. I do a
> > a key = stdscr.getch(), it registers the keys. But when I use a
> > subwindow (key = mysubwin.getch()), they don't register. No
> > exception dumped, but the arrow keys just don't register.
>
> Just to clarify, this means you are using the curses library.
>
Yes. At the top: "import curses".
> Its always useful if you can post some real code that shows
> the problem in action, otherwise we are debugging blind.
>
I thought about that, but it's a fair bit of code. However, I'll keep
this in mind for the future.
> > Has anyone else seen this behavior, and can you explain it?
>
> I'm guessing that you initialise the main screen using the
> standard initscr() settings? And you used keypad() to
> enable the function keys.
>
I called stdscr.keypad(True), and then, within a class method,
called mwin = stdscr.subwin(...), and then mwin.keypad(True). And it
didn't work, as described above (no arrow keys). So I grabbed the part
of the code relevant to this, and put it in a separate file, and
massaged it. That worked. Going back to the original code, I fiddled
with it, and somehow it now worked. So, problem solved for now.
For what it's worth, I wrote a whole bunch of curses test code in C
years ago-- testing colors, menus, forms, etc. Worked fine. But it's
probably been 19 years since then, and Python curses is just enough
different (with OOP and such) that it's mildly difficult.
>
> <Shameless plug>
> I have a book on programming curses with Python available
> on Amazon for a minimal price, both kindle and paper vesions.
>
> https://www.amazon.co.uk/gp/product/B091B85B77/ref=dbs_a_def_rwt_hsch_vapi_tkin_p1_i2
>
> </Shameless plug>
>
>
Actually, I have your ebook. (Might buy the paperback too; I like
physical media.) I'm only on the first chapter, though. I put a
different question on the Debian list, and someone suggested your book
and this list. So here I am.
Thanks.
Paul
--
Paul M. Foster
Personal Blog: http://noferblatz.com
Company Site: http://quillandmouse.com
Software Projects: https://gitlab.com/paulmfoster
More information about the Tutor
mailing list