Pythoncom 错误 IDLE (PumpMessage)

0 投票
1 回答
2182 浏览
提问于 2025-04-17 06:43

我在运行这个脚本的时候:

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'

这有点奇怪,因为在一个命令行窗口里导入了pythoncom,然后输入命令pythoncom.PumpMessages(),它就能正常运行。这个问题怎么解决呢?

1 个回答

4

看起来你在那个文件夹里有一个叫 pythoncom.py 的文件,这个文件被导入了,而不是我们真正需要的 pythoncom 模块。你可以试着把这个文件改个名字,然后再运行 click.py

撰写回答