Clear the IDLE contents with a command

Asked

Viewed 3,762 times

1

I’m creating a database which generates tables, but for the graphical part I’m not using any particular bookstore, like Tkinter, but only IDLE and some prompts.

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

This is the situation:

SS

  • Did you try to clean the IDLE screen before reexibiting the menu? Something like: http://stackoverflow.com/questions/1432480/any-way-to-clear-pythons-idle-window or http://stackoverflow.com/questions/517970/how-to-clear-python-interpreter-console

  • Well, give it a try that one and that one solutions also (there from the same links). The second is a very well voted very simple hack (which prints a large number of line feeds and makes seem that the screen became clean).

  • 1

    If it works (or pleases you), don’t forget to post a reply yourself here (of course, quoting the Soen font there). :)

1 answer

2

The answer to this question is nay, can not cancel with a Python command the contents of the interactive shell or IDLE, as can be done in Bash with the command clear. But there are at least 2 alternative solutions:

  1. Use a loop that iterates for a tot of times (for example 100) by making a print of an empty line, thus simulating the IDLE is being cleared. The following can 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 great deal of resources, and it takes a long time to clean the screen, and I don’t think it’s a great solution.

  2. Launch the program from the terminal, thus enjoying the command Bash clear. In this case, the program works much more smoothly, but always depends on a terminal.

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.