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

(Python Unicurses) stdscr not passing between files?

我一直在尝试学习 Curses(Unicurses,因为我在 Windows)并且一直在学习教程,但我被卡住了。我 运行 收到此错误消息:

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不包括在内,因为它没有任何相关信息,只是一个制作颜色的函数)

啊!我很笨。错误消息为我提供了我需要的所有信息——具体来说,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

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