(Python Unicurses)stdscr没有在文件之间传递?

时间:2015-06-08 01:31:12

标签: python windows curses

我一直在努力学习Curses(因为我在Windows上的Unicurses)并且一直在学习教程,但我已经陷入困境。我遇到此错误消息:

D:\Python34>python ./project/cursed.py
Traceback (most recent call last):
  File "./project/cursed.py", line 35, in <module>
    main()
  File "./project/cursed.py", line 20, in main
    obj_player = Player(stdscr, "@")
  File "D:\Python34\project\cursedplayer.py", line 10, in __init__
    self.max_x = stdscr.getmaxyx()[1] - 1
AttributeError: 'c_void_p' object has no attribute 'getmaxyx'

我可以从中收集到的是在尝试获取两个文件之间的stdscr变量时出现问题。这是具有我试图调用的函数的文件:

from unicurses import *
from cursedfunction import *

    class Player:

        def __init__(self, stdscr, body, fg = None, bg = None, attr = None):

            self.max_x = stdscr.getmaxyx()[1] - 1
            self.max_y = stdscr.getmaxyx()[0] - 1

            self.x = self.max_x / 2
            self.y = self.max_y / 2
            self.body = body

            del stdscr

            #create player

            self.window = newwin(1, 1, self.y, self.x)
            waddstr(self.window, self.body)
            self.panel = new_panel(self.window)

            self.fg = fg
            self.bg = bg
            self.color = 0
            self.attr = attr

            if (fg != None) and (bg != None):
                self.set_colors(fg, bg)

            self.show_changes()

        def set_colors(self, fg, bg):
            self.color = make_color(fg, bg)
            self.fg = fg
            self.bg = bg

            waddstr( self.window, self.body, color_pair(self.color) + self.attr)
            self.show_changes()

        def show_changes(self):
            update_panels()
            doupdate()

这是调用cursedplayer.py中定义的函数的主文件:

from unicurses import *
from cursedfunction import *
from cursedplayer import *
#lines is 80
#columns is 25

def main():

    stdscr = initscr()

    if not has_colors():
        print("You need colors to run!")
        return 0

    start_color()
    noecho()
    curs_set(False)
    keypad(stdscr, True)

    obj_player = Player(stdscr, "@")

    update_panels()
    doupdate()

    running = True
    while running:
        key = getch()
        if key == 27:
            running = False
            break

    endwin()

if (__name__ == "__main__"):
    main()

我很感激任何帮助。我一直在寻找,但没有找到任何与我的问题相关的东西。由于这个错误,我无法继续我正在关注的curses教程。谢谢你的阅读。

(不包括cursedfunction.py,因为它没有任何相关信息,只是一个产生颜色的函数)

1 个答案:

答案 0 :(得分:0)

啊!我很笨。错误消息给了我所需的所有信息 - 具体来说,stdscr没有一个名为'getmaxyx'的函数。我输错了命令!

从这里开始:

self.max_x = stdscr.getmaxyx()[1] - 1
self.max_y = stdscr.getmaxyx()[0] - 1

对此:

self.max_x = getmaxyx(stdscr)[1] - 1
self.max_y = getmaxyx(stdscr)[0] - 1

...能够以我需要的格式传递信息。为什么它在我不知道的教程中有效,但我责怪黑魔法。