Python创建窗口错误';错误的类型';

Python创建窗口错误';错误的类型';,python,glut,glutcreatewindow,Python,Glut,Glutcreatewindow,我正在尝试用python创建一个包含glut的窗口,并具有以下代码: glutInit() glutInitWindowSize(windowWidth, windowHeight) glutInitWindowPosition(int(centreX - windowWidth/2), int(centreY - windowHeight/2)) glutCreateWindow("MyWindow") glutInitDisplayMode(GLUT_SING

我正在尝试用python创建一个包含glut的窗口,并具有以下代码:

glutInit()
    glutInitWindowSize(windowWidth, windowHeight)
    glutInitWindowPosition(int(centreX - windowWidth/2), int(centreY - windowHeight/2))
    glutCreateWindow("MyWindow")
    glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB | GLUT_DEPTH)
    glutDisplayFunc(displayFun)
    glutIdleFunc(animateFun)
    glutKeyboardFunc(keyboardFun)
    glutPassiveMotionFunc(mouseFun)

    glutReshapeFunc(reshapeFun)
    initFun()
    #loadTextures()
    glutMainLoop()
我在“glutCreateWindow”行中得到一个错误,它说:

Traceback (most recent call last):
  File "F:\MyProject\main.py", line 301, in <module>
    glutCreateWindow("MyWindow")
  File "C:\Python34\lib\site-packages\OpenGL\GLUT\special.py", line 73, in glutCreateWindow
    return __glutCreateWindowWithExit(title, _exitfunc)
ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

我刚刚遇到了完全相同的问题,并找到了以下博客:


基本上,您需要指定在使用英特尔core duo的64位Windows 7上使用
b'Window Title'

传递字节数据,而不是字符串

已安装:python-3.4.0.amd64.exe

pip install image
pip install numpy
已从以下站点下载车轮组:

拥有PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl

试图安装 pip安装PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl

收到消息:

PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl is not supported wheel on this platform
升级的pip:

python -m pip --upgrade pip
升级后,它已成功安装

pip install PyOpenGL-3.1.1-cp34-cp34m-win_amd64.whl

pip install PyOpenGL_accelerate-3.1.1-cp34-cp34m-win_amd64.whl
要从以下位置运行代码:

出现错误:

ctypes.ArgumentError: argument 1: <class 'TypeError'>: wrong type

将调用从
glutCreateWindow(“名称”)
更改为
glutCreateWindow(b'name')
,除了在字符串前添加一个
b

b"MyWindow"
您还可以使用以下命令将字符串转换为ascii字节:

bytes("MyWindow","ascii")

有关更多详细信息,请参阅以下链接:

要最终解决此问题,您需要更改lib/site packages/OpenGL/GLUT/special.py文件的内容,如下所示:

def glutCreateWindow(title):
    """Create window with given title

    This is the Win32-specific version that handles
    registration of an exit-function handler 
    """
    return __glutCreateWindowWithExit(bytes(title,"ascii"), _exitfunc)
bytes("MyWindow","ascii")
def glutCreateWindow(title):
    """Create window with given title

    This is the Win32-specific version that handles
    registration of an exit-function handler 
    """
    return __glutCreateWindowWithExit(title.encode(), _exitfunc)
def glutCreateWindow(title):
    """Create window with given title

    This is the Win32-specific version that handles
    registration of an exit-function handler 
    """
    return __glutCreateWindowWithExit(bytes(title,"ascii"), _exitfunc)