首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python glutCreateWindow错误“错误类型”

Python glutCreateWindow错误“错误类型”
EN

Stack Overflow用户
提问于 2014-11-23 19:04:07
回答 4查看 9.2K关注 0票数 8

我正在尝试在python中创建一个具有create的窗口,并有以下代码:

代码语言:javascript
复制
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”行中看到一个错误,它是这样写的:

代码语言:javascript
复制
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

此函数的文档指定

代码语言:javascript
复制
int glutCreateWindow(char *name);
EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2014-11-26 16:28:09

我刚刚遇到了同样的问题,发现了这篇博客文章:

http://codeyarns.com/2012/04/27/pyopengl-glut-ctypes-error/

基本上,您需要指定正在传递字节数据,而不是使用b'Window Title'传递字符串。

票数 19
EN

Stack Overflow用户

发布于 2017-12-16 06:11:58

除了在字符串之前添加一个b之外:

代码语言:javascript
复制
b"MyWindow"

您还可以使用以下方法将字符串转换为ascii字节:

代码语言:javascript
复制
bytes("MyWindow","ascii")

有关更多细节,您可以参考以下链接:

PyOpenGL过剩类型错误

Python 3阅读器

票数 3
EN

Stack Overflow用户

发布于 2018-03-29 12:25:52

代码语言:javascript
复制
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)

为了最终解决这个问题,您需要更改lib/site-packages/OpenGL/GLUT/special.py文件的内容,如这样或这样:

代码语言:javascript
复制
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)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27093037

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档