如何在python curses中修复转换为参数2错误?

时间:2015-12-23 08:17:12

标签: python python-3.4 curses cpython python-curses

我在Unicurses工作,这是一个用于python的curses的跨平台模块。我试图将'@'字符放在我控制台的中心。我的代码是这样的:

from unicurses import *
def main():
    stdscr = initscr()
    max_y, max_x = getmaxyx( stdscr )
    move( max_y/2, max_x/2 )
    addstr("@")
    #addstr(str(getmaxyx(stdscr)))
    getch()
    endwin()
    return 0
if __name__ == "__main__" :
    main()

我一直收到错误

ctypes.ArgumentError was unhandled by user code
Message: argument 2: <class 'TypeError'>: Don't know how to convert parameter 2

这一行:

move( max_y/2, max_x/2 )

有没有人知道原因并修复此错误。谢谢!

1 个答案:

答案 0 :(得分:0)

问题是你要将浮点数传递给move函数,而你应该传递整数。使用整数除法运算符//代替/

from unicurses import *
def main():
    stdscr = initscr()
    max_y, max_x = getmaxyx( stdscr )
    move( max_y//2, max_x//2 ) # Use integer division to truncate the floats
    addstr("@")
    getch()
    endwin()
    return 0
if __name__ == "__main__" :
    main()