我尝试使用 JS 创建一个应用程序来登录https://www.easports.com/fifa/ultimate-team/web-app/#,但无法单击“登录”按钮。
调用按钮元素上的单击。
document.getElementsByTagName("button")[0].click()
Run Code Online (Sandbox Code Playgroud)
什么都没发生。如果我用鼠标移动并单击它,它就会起作用。
QThread 有一个完成的信号,当线程完成时我可以做一些事情(连接到一个方法/函数),但是我也想用 QRunnable 来做这件事。有没有办法在完成后将 QRunnable 线程连接到方法/函数?
Q线程:
class HelloWorldTask(QThread):
def __init__(self):
QThread.__init__(self)
def run(self):
import time
time.sleep(3)
print ("Running thread \n")
time.sleep(3)
hello.finished.connect(check)
def check():
print('Thread Done')
Run Code Online (Sandbox Code Playgroud)
输出:
运行线程
完成的
QRunnable:
instance = QThreadPool.globalInstance()
class HelloWorldTask(QRunnable):
def __init__(self):
super().__init__(self)
def run(self):
import time
time.sleep(3)
print ("Running thread \n")
time.sleep(3)
hello = HelloWorldTask()
#hello.finished.connect(check) <-- how to connect to a method/function when finished.
instance.start(hello)
print(instance.waitForDone())
def check():
print('Thread Done')
Run Code Online (Sandbox Code Playgroud)
所需的输出:
运行线程
线程完成
我想向 QMessagebox 添加一个自定义按钮,用于打开 matplotlib 窗口,以及一个“确定”按钮,供用户在想要关闭它时单击
我目前已经可以正常工作了,但我希望这两个按钮能够执行单独的操作而不是打开窗口。
我知道我可以创建一个具有所需结果的对话框窗口,但我想知道如何使用 QMessageBox。
import sys
from PyQt5 import QtCore, QtWidgets
def main():
app = QtWidgets.QApplication(sys.argv)
msgbox = QtWidgets.QMessageBox()
msgbox.setWindowTitle("Information")
msgbox.setText('Test')
msgbox.addButton(QtWidgets.QMessageBox.Ok)
msgbox.addButton('View Graphs', QtWidgets.QMessageBox.YesRole)
bttn = msgbox.exec_()
if bttn:
print("Ok")
else:
print("View Graphs")
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Run Code Online (Sandbox Code Playgroud)
期望的结果:
确定按钮 - 关闭 QMessageBox
“查看图形”按钮 - 打开 matplotlib 窗口并保持 QMessageBox 打开,直到用户单击“确定”