【问题标题】:PySide2: window is not respondingPySide2:窗口没有响应
【发布时间】:2020-05-24 21:10:00
【问题描述】:

在 mouse.wait 函数之前打开窗口时没有响应。 如果将 mouse.wait 函数替换为另一个(不等待鼠标点击),窗口将正常打开。

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_())

【问题讨论】:

    标签: python mouseevent pyside2 pyautogui python-3.8


    【解决方案1】:

    问题在于等待方法通过冻结 GUI 来阻塞 Qt 事件循环。一个可能的解决方案是在另一个线程中运行它:

    import threading
    
    # ...
    
    def execute_thread():
        threading.Thread(target=prog, daemon=True).start()
    
    def menu():
        mui.configButton.clicked.connect(execute_thread)
    
    # ...
    

    【讨论】:

      猜你喜欢
      • 2018-10-16
      • 2021-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-15
      • 1970-01-01
      • 2015-12-21
      • 2021-10-09
      相关资源
      最近更新 更多