Clear the contents of IDLE with a command

1
I'm creating a database that generates tables, but for the graphical part I'm not using any particular bookstore, like TkInter, but only the IDLE and some prompts.

/ p>

But I would like to improve the part of the database menu. One problem is that when I choose an option, and this is done, then the prompt is shown again, because I use a while loop , which only ends when the user clicks the number 6. Is it possible, for example, to delete the previous menu before showing the new one?

Here's the situation:

    
asked by anonymous 29.10.2014 / 22:35

1 answer

2

The answer to this question is no , you can not cancel the interactive shell or IDLE content with a Python command like you can in Bash with command clear . There are, however, at least 2 alternative solutions:

  • Use a loop that iterates for a tot of times (eg 100) by making a print of an empty line, thus simulating that IDLE is being cleaned. The following may be an example of the simple code:

    def clear(times=100):
        """simulates the cleanning of the IDLE"""
        if isinstance(times, int):
            for i in range(times):
                print()
    

    The problem with this solution is that the call to print() requires a lot of resources, and it takes a lot of time to clean the screen, and I do not think it's a great solution.

  • Clear the program from the terminal , thus taking advantage of the Bash clear command. In this case, the program works much more smoothly, but always depends on a terminal.

  • If you know other solutions, do not hesitate to propose;)

        
    12.01.2015 / 02:34