Re: clear shell screen

Discussion in 'Python' started by Gabriel Genellina, Oct 29, 2007.

  1. En Mon, 29 Oct 2007 17:31:52 -0300, Shawn Minisall
    <> escribió:

    > Hmm...it works fine within the command line but then when I import os in
    > python and then try os.system("cls"), i get that very fast
    > opening/closing window and 0 inside the shell.


    Try the other method menctioned in the Knowledge Base article:

    <code>
    """
    How To Performing Clear Screen (CLS) in a Console Application

    From http://support.microsoft.com/kb/99261

    Some non-Microsoft versions of C++ provide a clrscr function
    for clearing the screen in a DOS application. However, there
    is no Win32 Application Programming Interface (API) or
    C-Runtime function that will perform this function.
    To accomplish this task for a Win32 console application, use
    one of the following methods:
    - os.system("cls")
    - Write a function that will programmatically clear the screen

    The following function is my (GG) Python translation of the
    original C code as published in the Microsoft article, using
    Mark Hammond's pywin32 extensions:
    """

    import win32api
    import win32console

    def cls():
    "Clear console screen"
    TopLeft = win32console.PyCOORDType(0,0)
    csb = win32console.GetStdHandle(win32api.STD_OUTPUT_HANDLE)
    csbi = csb.GetConsoleScreenBufferInfo()
    size = csbi['Size'].X * csbi['Size'].Y;
    csb.FillConsoleOutputCharacter(u' ', size, TopLeft)
    csb.FillConsoleOutputAttribute(csbi['Attributes'], size, TopLeft);
    csb.SetConsoleCursorPosition(TopLeft)

    </code>

    --
    Gabriel Genellina
     
    Gabriel Genellina, Oct 29, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. A. L.
    Replies:
    5
    Views:
    65,923
    bruce
    Sep 16, 2005
  2. Shawn Minisall

    clear shell screen

    Shawn Minisall, Oct 29, 2007, in forum: Python
    Replies:
    1
    Views:
    664
    Tim Roberts
    Oct 31, 2007
  3. Gabriel Genellina

    Re: clear shell screen

    Gabriel Genellina, Oct 29, 2007, in forum: Python
    Replies:
    0
    Views:
    501
    Gabriel Genellina
    Oct 29, 2007
  4. Shawn Minisall

    Re: clear shell screen

    Shawn Minisall, Oct 29, 2007, in forum: Python
    Replies:
    1
    Views:
    570
    Dennis Lee Bieber
    Oct 30, 2007
  5. owl
    Replies:
    2
    Views:
    882
Loading...

Share This Page