考虑以下代码:
#!/usr/bin/env python
from Xlib.display import Display
import os
def main():
disp = Display() # connect to display
while True:
print("1")
event = disp.next_event()
print("2")
if event.type == Xlib.protocol.event.KeyPress:
print("keypress!")
if __name__ == '__main__':
main()
此代码输出1
,但不输出2
。它好像挂在显示器上。为什么会这样?非常感谢。你知道吗
方法next\u event()是一个阻塞方法,请参见documentation:
如果它被阻止,那是因为还没有任何事件到达。你知道吗
相关问题 更多 >
编程相关推荐