简体   繁体   English

PySide2:window 没有响应

[英]PySide2: window is not responding

问题

Window is not responding when opened before the mouse.wait function. Window 在鼠标打开之前没有响应。等待 function。 If replace the mouse.wait function to another (which doesn't waiting the mouse click), the window will open normally.如果将mouse.wait function替换为另一个(不等待鼠标点击),window将正常打开。

import pyautogui, sys, mouse
from PySide2 import QtWidgets
from design import Ui_Form, Ui_Next

def mpos(file):
    mouse.wait(button='right', target_types='down')
    x,y=pyautogui.position()
    file.write(str(x)+'_'+str(y)+'-')

def prog():
    with open('prog.txt', 'w') as file:
        next()
        mpos(file)
        next()
        mpos(file)
        next()
        mpos(file)

def menu():
    mui.configButton.clicked.connect(prog)
    wmenu.show()

def fclose():
    wnext.close()

def next():
    nui.okButton.clicked.connect(fclose)
    wnext.show()

app = QtWidgets.QApplication(sys.argv)

wmenu = QtWidgets.QFrame()
mui = Ui_Form()
mui.setupUi(wmenu)

wnext = QtWidgets.QFrame()
nui = Ui_Next()
nui.setupUi(wnext)

menu()
sys.exit(app.exec_())

The problem is that the wait method blocks the Qt event loop by freezing the GUI.问题是 wait 方法通过冻结 GUI 来阻止 Qt 事件循环。 A possible solution is to run it in another thread:一个可能的解决方案是在另一个线程中运行它:

import threading

# ...

def execute_thread():
    threading.Thread(target=prog, daemon=True).start()

def menu():
    mui.configButton.clicked.connect(execute_thread)

# ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM