pmbarrett314 / curses-menu

A simple console menu system in python using the curses library
MIT License
475 stars 53 forks source link

Screen not getting cleared between menus #29

Closed ianling closed 4 years ago

ianling commented 7 years ago

Try this example:

from cursesmenu import SelectionMenu
SelectionMenu.get_selection(["Item 1",
                             "Item 2",
                             "Item 3",
                             "Item 4",
                             "Item 5",
                             "Item 6"], 'Menu Title')
SelectionMenu.get_selection(["Second thing 1",
                             "Second thing 2"], 'Menu Title')

Here's a screenshot: http://i.imgur.com/kjqnWAI.png

To fix this, I changed line 349 of curses_menu.py to the following:

def clear_screen(self):
    """
    Clear the screen belonging to this menu
    """
    self.screen.clear()
    screen_rows, screen_cols = CursesMenu.stdscr.getmaxyx()
    top_row = 0
    self.screen.refresh(top_row, 0, 0, 0, screen_rows - 1, screen_cols - 1)

I'm not sure why self.screen.clear() wasn't getting the job done by itself. I also tried simply adding self.draw(), which mostly worked, but caused parts of the menu to not show up until you selected them.

I have a feeling this fix is more of a bandaid than an actual fix, so I didn't submit a pull request.

fiendish commented 6 years ago

This is a real issue, but I think actually a better fix is to call CursesMenu.stdscr.clear() before the call to curses.newpad in _main_loop.