2011-03-02 2 views
5

print() 함수를 사용하여 DOS 명령 창 (Windows 7을 사용하고 있습니다)으로 출력을 보내는 Python 스크립트가 있지만 다음 사용 가능한 출력 위치에서 커서가 깜박 거리지 않도록하고 싶습니다. 내가 어떻게이 일을 할 수 있는지 알았어? DOS 명령 목록을 살펴 봤지만 적합한 항목을 찾을 수 없습니다.명령 창에서 깜박이는 커서를 끄는 방법은 무엇입니까?

도움을 주시면 감사하겠습니다. Alan

+0

내가 알 수있는 한, 표준 DOS 명령 창을 사용하여이를 수행 할 수 없습니다. 직접 출력 창을 제공해야합니다. TKInter 또는 wxPython을 사용합니다. 답장을 보내 주셔서 감사합니다. – kindall

답변

3

curses 모듈에는 Windows 포트가 없으므로 필요한 포트 일 가능성이 큽니다. 귀하의 필요를 충족시키는 데 가장 가까운 것은 Console module입니다 (effbot.org의 Fredrik Lundh 작성). 불행하게도이 모듈은 파이썬 3 이전 버전에서만 사용 가능합니다.

파이썬 2.6/WinXP에서 다음 코드는 콘솔 창을 열고, 커서를 보이지 않게 만들고, 'Hello, world!'를 출력합니다. 그리고 두 개의 초 후 콘솔 창을 닫습니다 :

import Console 
import time 

c = Console.getconsole() 
c.cursor(0) 
print 'Hello, world!' 
time.sleep(2) 
+0

당신 말이 맞아요 - 나는 파이썬 3.1을 사용하고있어서 잠시 동안 커서가 붙어있는 것처럼 보입니다 .--(안부. –

9

내가 파이썬 색상 파노라마 (http://pypi.python.org/pypi/colorama)와 함께 사용하는 크로스 플랫폼 색상 라이브러리를 작성했습니다

import sys 
import os 

if os.name == 'nt': 
    import msvcrt 
    import ctypes 

    class _CursorInfo(ctypes.Structure): 
     _fields_ = [("size", ctypes.c_int), 
        ("visible", ctypes.c_byte)] 

def hide_cursor(): 
    if os.name == 'nt': 
     ci = _CursorInfo() 
     handle = ctypes.windll.kernel32.GetStdHandle(-11) 
     ctypes.windll.kernel32.GetConsoleCursorInfo(handle, ctypes.byref(ci)) 
     ci.visible = False 
     ctypes.windll.kernel32.SetConsoleCursorInfo(handle, ctypes.byref(ci)) 
    elif os.name == 'posix': 
     sys.stdout.write("\033[?25l") 
     sys.stdout.flush() 

def show_cursor(): 
    if os.name == 'nt': 
     ci = _CursorInfo() 
     handle = ctypes.windll.kernel32.GetStdHandle(-11) 
     ctypes.windll.kernel32.GetConsoleCursorInfo(handle, ctypes.byref(ci)) 
     ci.visible = True 
     ctypes.windll.kernel32.SetConsoleCursorInfo(handle, ctypes.byref(ci)) 
    elif os.name == 'posix': 
     sys.stdout.write("\033[?25h") 
     sys.stdout.flush() 

위는 선택적 사본 & 붙여 넣기입니다 : 3. 완전히 Windows 또는 Linux에 커서를 숨기려면. 여기에서 당신은 당신이 원하는 것을 거의 할 수 있어야합니다. 복사 및 붙여 넣기를 망쳐 놓지 않았다고 가정하면 Windows Vista 및 Linux/Konsole에서 테스트되었습니다.