首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Visual 2013中使用UniCurses

如何在Visual 2013中使用UniCurses
EN

Stack Overflow用户
提问于 2015-10-08 01:50:26
回答 1查看 464关注 0票数 0

我正在努力学习Python,这样我就可以在我正在进行的项目中使用它了。

我用的是:

  • Python 2.7
  • 2013
  • 用于2013的Python工具

我安装了必要的项目,UniCurses和PDCurses。而且它似乎在Python解释器和空闲环境下工作得很好。但不是在..。

我一直收到一个错误,说pdcurses.dll不见了。因此,我决定将PDCurses文件复制到项目的根目录中。这似乎解决了缺少的pdcurses.dll错误。

然而,UniCurses仍然不能正常工作。当我尝试使用任何UniCurses函数时,我都会得到一个AttributeError: 'c_void_p' object has no attribute 'TheAttribute'。除了我第一次输入对象: UniCurses之外,每个stdscr = unicurses.initscr()函数都会发生这种情况。

因此,我开始研究一些教程,以确保安装正确。我遵循了UniCurses自述在GitHub:https://www.youtube.com/watch?v=6u2D-P-zuno上的说明,以及关于YouTube:https://www.youtube.com/watch?v=6u2D-P-zuno的安装教程和我仍然无法使它工作。

我确实在这里找到了一篇与我的问题有点相似的文章,但对我的问题并没有真正的帮助。您可以在这里查看:(Python Unicurses) stdscr not passing between files?

有人知道我做错了什么吗?我花了几个小时来寻找解决方案,但什么也没有奏效。

任何援助都是非常感谢的。谢谢!

EN

回答 1

Stack Overflow用户

发布于 2015-10-08 19:25:38

,我想明白了!对我来说,不幸的是,我太专注于学习教程中忽略了根本问题的例子。当我在这里发现类似的帖子(链接包括在我的问题中)时,我就应该注意到,但是我认为我遇到的问题是不同的。

基本上,我认为UniCurses和/或PDCurses设置错误,从而导致无法访问这些方法。但事实并非如此。相反,我所遵循的教程中的代码实际上是错误地访问这些方法(不知道它为什么对它们起作用,也许是旧版本?)。

下面是一个示例:

代码语言:javascript
复制
import unicurses

# Init screen object
stdscr = unicurses.initscr()

# Incorrect way to access methods:
stdscr.addstr('Hello World!')

# Correct way to access methods:
unicurses.addstr('Hello World!')

代码语言:javascript
复制
from unicurses import *

# Init screen object
stdscr = initscr()

# Incorrect way to access methods:
stdscr.addstr('Hello World!')

# Correct way to access methods:
addstr('Hello World!')

直到我在网上找到了这个UniCurses安装测试脚本,我才真正意识到这个问题:

代码语言:javascript
复制
# Script to test the installation of UniCurses
from unicurses import *

stdscr = initscr() # initializes the standard screen
addstr('Hello World!\n')
addch(ord('A') | A_BOLD)
addstr(' single bold letter\n')
attron(A_BOLD) # Turns on attribute
addstr('\n\nBold string')
attroff(A_BOLD)
addstr("\nNot bold now")
mvaddch(7, 10, 66); #B at row 7, col 10
addstr(' - single letter at row 7, col 10')

start_color()
init_pair(1, COLOR_RED, COLOR_GREEN) # Specifies foreground and background pair 1
init_pair(2, COLOR_YELLOW, COLOR_RED)

attron(COLOR_PAIR(1))
mvaddstr(15, 12, 'Red on green at row 15, col 12')
attroff(COLOR_PAIR(1))

attron(COLOR_PAIR(2))
addstr('\n\nYellow on red')
addstr('\n\nPress up arrow!')
attroff(COLOR_PAIR(2))

cbreak() # Gets raw key inputs but allows CRTL+C to work
keypad(stdscr, True)  # Get arrow keys etc.
noecho() # Do not display automatically characters for key presses
a = getch() # Gets the key code
if a == KEY_UP:
    beep()
    clear()
    addstr('Beep! Any key to quit.')
a = getch()

(资料来源:http://www.pp4s.co.uk/main/tu-python-unicurses.html)

我希望这会对其他遇到这个问题的人有所帮助。我肯定是因为自己没能更快的赶上而自责。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33005297

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档