码迷,mamicode.com
首页 > 其他好文 > 详细

pyqtthreading(网友提供)

时间:2014-11-04 17:01:15      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:blog   http   io   ar   os   for   sp   on   2014   

import threading

import sys, time

from PyQt4 import QtCore, QtGui

import psutil

import os

 

class MainWindow(QtGui.QMainWindow):

    def __init__(self):

        super(MainWindow, self).__init__()

 

        self.main_layout = QtGui.QVBoxLayout()

 

        ok_button = QtGui.QPushButton("Run")

        ok_button.clicked.connect(self.OK)      

        self.main_layout.addWidget(ok_button)       

 

        cancel_button = QtGui.QPushButton("Cancel")

        cancel_button.clicked.connect(self.cancel)      

        self.main_layout.addWidget(cancel_button)

 

        central_widget = QtGui.QWidget()

        central_widget.setLayout(self.main_layout)

        self.setCentralWidget(central_widget)

 

    def myEvenListener(self,stop_event):

        state=True

        while state and not stop_event.isSet():

            for i in range(10,100):

                time.sleep(i*0.01)

                print ‘.‘*i

 

    def OK(self):

        self.stop_event=threading.Event()

        self.c_thread=threading.Thread(target=self.myEvenListener, args=(self.stop_event,))

        self.c_thread.start()       

 

    def cancel(self):

        self.stop_event.set()

        self.close()    

 

def main():

    app = QtGui.QApplication(sys.argv)

    window = MainWindow()

    window.resize(480, 320)

    window.show()

    app.exec_()

main()

 

 

def kill_proc_tree(pid, including_parent=True):    

    parent = psutil.Process(pid)

    if including_parent:

        parent.kill()

 

me = os.getpid()

kill_proc_tree(me)

 如图:bubuko.com,布布扣

pyqtthreading(网友提供)

标签:blog   http   io   ar   os   for   sp   on   2014   

原文地址:http://www.cnblogs.com/mhxy13867806343/p/4073940.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!