[英]Curses library in python
I have C code which draws a vertical & a horizontal line in the center of screen as below:我有 C 代码,它在屏幕中央绘制一条垂直线和一条水平线,如下所示:
#include<stdio.h>
#define HLINE for(i=0;i<79;i++)\
printf("%c",196);
#define VLINE(X,Y) {\
gotoxy(X,Y);\
printf("%c",179);\
}
int main()
{
int i,j;
clrscr();
gotoxy(1,12);
HLINE
for(y=1;y<25;y++)
VLINE(39,y)
return 0;
}
I am trying to convert it literally in python version 2.7.6:我试图在 python 版本 2.7.6 中逐字转换它:
import curses
def HLINE():
for i in range(0,79):
print "%c" % 45
def VLINE(X,Y):
curses.setsyx(Y,X)
print "%c" % 124
curses.setsyx(12,1)
HLINE()
for y in range(1,25):
VLINE(39,y)
My questions:我的问题:
1.Do we have to change the position of x and y in setsyx function ie, gotoxy(1,12) is setsyx(12,1) ? 1.我们是否必须改变setsyx函数中x和y的位置,即gotoxy(1,12)是setsyx(12,1)?
2.Curses module is only available for unix not for windows?If yes, then what about windows(python 2.7.6)? 2.Curses 模块只适用于 unix,不适用于 windows?如果是,那么 windows(python 2.7.6) 呢?
3.Why character value of 179 and 196 are in python but in C, it is | 3.为什么179和196的字符值在python中是 而在C中却是| and - respectively?
和 - 分别?
4.Above code in python is literally right or it needs some improvement? 4.python 中的以上代码字面上是正确的还是需要一些改进?
setsyx(y, x)
and gotoxy(x, y)
setsyx(y, x)
和gotoxy(x, y)
#!/usr/bin/python
line) as this forces python to work with utf-8 encoding in String objects:#!/usr/bin/python
行之后),因为这会强制 python 在 String 对象中使用 utf-8 编码: # -*- coding: utf-8 -*-
curses.ACS_HLINE
and curses.ACS_VLINE
.curses.ACS_HLINE
和curses.ACS_VLINE
。print
and curses
functions, it will mess up the display.print
和curses
功能,它会弄乱显示。 Use curses.addch
or variants instead.curses.addch
或变体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.