Pythoncom错误IDLE(PumpMessage)

时间:2011-11-20 23:33:42

标签: python shell python-idle pythoncom

尝试运行此脚本:

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()后它运行没有任何问题。怎么可能解决这个问题?

1 个答案:

答案 0 :(得分:3)

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