我试图设计一个pyqt gui,当我按下start时它启动函数fun1并在funbrowser中启动selenium脚本。当我按下“停止”时,我的意图是,无论funbrowser中的控件在哪里,函数funbrowser都会停止运行。并且pyqt窗口应该关闭,程序必须停止。但它仍然打印“HI”我正在使用spyder windows 7 python 3.6 那么我应该连接到按钮停止,以便有趣的浏览器停止。
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def funbrowser(self,browser,details):
browser.get("https://fileml.com/l/0w5O")
time.sleep(1)
browser.switch_to.frame("offer-iframe")
elemlist=browser.find_elements_by_xpath("//ul/li/a")
list_of_names=[] #All those present
for i in range(len(elemlist)):
list_of_names.append(str(elemlist[i].text))
print("\n")
print(list_of_names)
lon=len(list_of_names)*[0]
available=[] #All those linked
for i in range(len(elemlist)):
if "Register for Free" in elemlist[i].text:
lon[i]="register"
available.append("register")
if "Health Samples" in elemlist[i].text:
lon[i]="health"
available.append("health")
print("Available",available)
print("lon",lon)
selected=random.choice(available)
print("selected is ",selected)
clickon=lon.index(selected)
print(clickon)
elemlist[clickon].click()
alert = browser.switch_to.alert
alert.accept()
def fun1(self):
browser=webdriver.Firefox()
self.funbrowser(browser,details)
def fun2(self):
import sys
self.hide()
quit()
print("..")
def launch_thread(self):
import threading
x=threading.Thread(target=self.fun1)
x.start()
def initUI(self):
self.setGeometry(300, 300, 300, 220)
self.setWindowTitle('Icon')
self.setWindowIcon(QIcon('web.png'))
self.layout=QtWidgets.QGridLayout()
self.btn1=QtWidgets.QPushButton("start",self)
self.btn1.clicked.connect(self.launch_thread)
self.btn2=QtWidgets.QPushButton("stop",self)
self.btn2.clicked.connect()
self.btn3=QtWidgets.QPushButton("quit",self)
self.btn3.clicked.connect(self.close)
self.layout.addWidget(self.btn1,0,0)
self.layout.addWidget(self.btn2,0,1)
self.layout.addWidget(self.btn3,0,2)
self.setLayout(self.layout)
self.show()
我应该有什么功能连接到self.btn2(“停止”)