我一直在尝试学习诅咒(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()我很感谢你的帮助。我一直在寻找,但没有发现任何与我的问题有关的东西。由于这个错误,我无法继续执行我所遵循的诅咒教程。感谢您的阅读。
(不包括cursedfunction.py,因为它没有任何相关信息,只是一个制作颜色的函数)
发布于 2015-06-08 02:16:02
阿!我很笨。错误信息给了我所有我需要的信息--特别是,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...was能够以我需要的格式传递信息。我不知道它为什么会在教程中起作用,但我把责任归咎于黑魔法。
https://stackoverflow.com/questions/30700150
复制相似问题