종종 파이썬 시작하는사람들중에 c처럼 익숙해지기위해서 콘솔로 게임 만들어보는 사람들이 있는데 gotoxy같은것들이 없어서 찾다가 포기하고 tkinter같은걸 이용해서 어색하게 gui로 만드는걸 봐서...
1. c언어 gotoxy함수를 파이썬으로 구현해보기.
구글링해봤을때 확 나오는게 없길래 없는줄알았는데 의외로 네이버에서 발견...
http://foreblog.tistory.com/812 아니면 win32api가 설치되있는분들은 이렇게 간단하게 가능...
# -*- encoding: cp949 -*- import win32api from ctypes import Structure, c_short, windll, POINTER def gotoxy(x,y): class COORD(Structure): _fields_=[("X",c_short),("Y",c_short)] windll.kernel32.SetConsoleCursorPosition(win32api.GetStdHandle(win32api.STD_OUTPUT_HANDLE), (COORD(x,y))) gotoxy(40,10) print 'move~'
2. colorama 모듈.
c에서의 콘솔 게임과 같은 분위기를 위해서 글자 색이나 배경 색을 바꿔줄 시(또는 디버깅 시 특정 값만 다른 색으로 출력해서 확인할 경우.) colorama모듈 사용 가능..
https://pypi.python.org/pypi/colorama 아래는 예제 코드.
# -*- encoding: cp949 -*- from colorama import init from colorama import Fore, Back, Style init() print(Fore.RED + 'some red text') print Fore.BLUE+'blue!'+Fore.CYAN print(Back.GREEN + 'and with a green background') print(Style.DIM + 'and in dim text') print(Style.RESET_ALL) print('back to normal now')
'Python > 2.7 information' 카테고리의 다른 글
파이썬 내부구조 이해하기. 2.x (0) | 2016.02.27 |
---|---|
python lambda function (0) | 2016.02.08 |
지도 모듈 (구글맵, folium 등등.) (0) | 2015.12.24 |
Hello world 난독화하기.(번역) (1) | 2015.11.28 |
수학 관련 모듈 sympy, scipy (0) | 2015.09.07 |