Pythoncom 错误 IDLE (PumpMessage)

发布于 2024-12-17 04:17:16 字数 1128 浏览 1 评论 0原文

尝试运行此脚本:

import pythoncom, pyHook 

def OnMouseEvent(event):
    # called when mouse events are received
    print 'MessageName:',event.MessageName
    print 'Message:',event.Message
    print 'Time:',event.Time
    print 'Window:',event.Window
    print 'WindowName:',event.WindowName
    print 'Position:',event.Position
    print 'Wheel:',event.Wheel
    print 'Injected:',event.Injected
    print '---'

    # return True to pass the event to other handlers
    return True

# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.MouseAll = OnMouseEvent
# set the hook
hm.HookMouse()
# wait forever
pythoncom.PumpMessages()

我收到一个错误:

Traceback (most recent call last):
  File "C:\Python26\Test\click.py", line 1, in <module>
    import pythoncom, pyHook
  File "C:\Python26\Test\pythoncom.py", line 13, in <module>
    pythoncom.PumpMessages() #will wait forever
AttributeError: 'module' object has no attribute 'PumpMessages'

这很奇怪,因为在 shell 中导入 pythoncom 并编写命令 pythoncom.PumpMessages() 之后,它运行没有任何问题。这个问题该如何解决呢?

Trying to run this script:

import pythoncom, pyHook 

def OnMouseEvent(event):
    # called when mouse events are received
    print 'MessageName:',event.MessageName
    print 'Message:',event.Message
    print 'Time:',event.Time
    print 'Window:',event.Window
    print 'WindowName:',event.WindowName
    print 'Position:',event.Position
    print 'Wheel:',event.Wheel
    print 'Injected:',event.Injected
    print '---'

    # return True to pass the event to other handlers
    return True

# create a hook manager
hm = pyHook.HookManager()
# watch for all mouse events
hm.MouseAll = OnMouseEvent
# set the hook
hm.HookMouse()
# wait forever
pythoncom.PumpMessages()

I receive an error:

Traceback (most recent call last):
  File "C:\Python26\Test\click.py", line 1, in <module>
    import pythoncom, pyHook
  File "C:\Python26\Test\pythoncom.py", line 13, in <module>
    pythoncom.PumpMessages() #will wait forever
AttributeError: 'module' object has no attribute 'PumpMessages'

It's strange, because after importing a pythoncom in a shell and writing the command pythoncom.PumpMessages() it runs without any problem. How could be this issue solved?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

想挽留 2024-12-24 04:17:16

看起来您在该文件夹中有一个文件 pythoncom.py ,该文件正在导入,而不是真正的 pythoncom 模块。尝试将该文件重命名为其他名称,然后运行 ​​click.py

It looks like you've got a file pythoncom.py in that folder, which is being imported instead of the real pythoncom module. Try renaming that file to something else, then running click.py.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文