# -*- coding: utf-8 -*-

 import sys, time
from PyQt4.QtCore import *
from PyQt4.QtGui import *
x = 0
class Window(QWidget):
def __init__(self, parent = None):
QWidget.__init__(self, parent)
self.thread = Worker() # 提示信息
self.xLable = QLabel("Number of xTimes:")
# 下拉框
self.spinBox = QSpinBox()
self.spinBox.setMaximum(100)
self.spinBox.setValue(10)
self.startButton = QPushButton(self.tr("&Start"))
# 布局
layout = QGridLayout()
layout.addWidget(self.xLable, 0, 0)
layout.addWidget(self.spinBox, 0, 1)
layout.addWidget(self.startButton, 0, 2)
self.setLayout(layout)
# 标题
self.setWindowTitle(self.tr("Threading")) # 信号
self.connect(self.thread, SIGNAL("finished()"), self.finishSend)
self.connect(self.thread, SIGNAL("update(int)"), self.updateGUIStatus)
self.connect(self.startButton, SIGNAL("clicked()"), self.sendAdvMail) def sendAdvMail(self):
self.spinBox.setReadOnly(True)
self.startButton.setEnabled(False)
#传递值到线程中
self.thread.render(self.spinBox.value()) def updateGUIStatus(self, leftTime):
self.xLable.setText(str(leftTime)) def finishSend(self):
self.spinBox.setReadOnly(False)
self.startButton.setEnabled(True) class Worker(QThread):
def __init__(self, parent = None):
QThread.__init__(self, parent)
self.exiting = False
self.xTimes = 0 def __del__(self):
self.exiting = True
self.wait() def render(self, xTimes):
self.xTimes = xTimes
self.start() def run(self):
# Note: This is never called directly. It is called by Qt once the
# thread environment has been set up.
n = self.xTimes
while not self.exiting and n > 0:
time.sleep(1)
#该信号引起界面更新
n -= 1
self.emit(SIGNAL("update(int)"), n) if __name__ == "__main__":
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())

编辑器加载中...

【多线程】python界面阻塞,白屏,not responding解决的简单例子的更多相关文章

  1. Android Activity启动黑/白屏原因与解决方式

    Android Activity启动黑/白屏原因与解决方式 我们新建一个HelloWorld项目,运行在手机上时,Activity打开之前会有一个动画,而这个动画里是全白或者全黑的(取决于你的主题是亮 ...

  2. WebView 5.0+闪烁以及白屏问题完美解决

    Android webView 在5.0+上启动硬件加速,造成部分手机出现闪烁.白屏等现象 必须写下这篇博客,遇到的问题搞了很久,百度谷歌就是没有完整的答案,记录下来,方便博友们: 需求:一个简单的W ...

  3. Qt for Android 启动短暂的黑屏或白屏问题如何解决?

    解决方法一: 使用透明主题 点击项目 -> 在 构建设置 里面找到 Build Android APK 栏目,点击 create templates 创建一个 AndroidManifest.x ...

  4. VC 窗口出现白屏闪烁的解决办法

    处理一下窗口的WM_ERASEBKGND消息即可. 在messagemap里添加ON_WM_ERASEBKGND() 在窗口头文件里添加 afx_msg BOOL OnEraseBkgnd(CDC* ...

  5. Android应用启动会白屏一下的解决办法

    设置透明样式,如下:<activity android:name="com.hongfans.cvi.ui.MainActivity" android:configChang ...

  6. Python网络编程UDP服务器与客服端简单例子

    [转载] https://blog.csdn.net/hu330459076/article/details/7868028 UDP服务器代码: #!/usr/bin/env python # -*- ...

  7. Genymotion开启就全部白屏解决方法

    Genymotion开启就整个界面全部白屏,包括菜单栏也白屏,解决方法: 很可能是显卡驱动有问题,用驱动人生或者驱动精灵更新显卡驱动就可以了. 目前开发者好用的模拟器有: 1.Genymotion 2 ...

  8. Silverlight网页打开后马上崩溃,“白屏”,而且毫无提示

    如题,出现白屏的问题 在Application_UnhandledException函数内,跟踪异常e的提示信息,可以了解到如下信息: at System.ComponentModel.AsyncCo ...

  9. react native 完美解决启动白屏

    先讲下我的RN版本0.58.5 首先安装react-native-splash-screen(目前使用的版本是3.2.0) 项目地址https://github.com/crazycodeboy/re ...

随机推荐

  1. Bootstrap相关优质项目学习清单

    1:编码规范 by @mdo编写灵活.稳定.高质量的 HTML 和 CSS 代码的规范 http://codeguide.bootcss.com/ 2:快速.可靠.安全的依赖管理工具.Yarn 缓存了 ...

  2. 【微信小程序】自定义模态框实例

    原文链接:https://mp.weixin.qq.com/s/23wPVFUGY-lsTiQBtUdhXA 1 概述 由于官方API提供的显示模态弹窗,只能简单地显示文字内容,不能对对话框内容进行自 ...

  3. spring mvc controller间跳转 重定向 传参(转)

    spring mvc controller间跳转 重定向 传参 url:http://zghbwjl.blog.163.com/blog/static/12033667220137795252845/ ...

  4. href=“file://” doesn't work

    Local Explorer 2016.6.21.0 CRX for Chrome or Chromium https://www.crx4chrome.com/extensions/eokekhgp ...

  5. [Http] Understand what an HTTP Request is

    Let's look at several HTTP requests to learn the basic structure of these messages, and how the vari ...

  6. [Recompose] Add Local State to a Functional Stateless Component using Recompose

    Learn how to use the 'withState' and 'withHandlers' higher order components to easily add local stat ...

  7. 终端中经常使用的shell 命令

    Mac 在shell命令终端中,Ctrl+n相当于方向向下的方向键,Ctrl+p相当于方向向上的方向键. 在命令终端中通过它们或者方向键能够实现对历史命令的高速查找.这也是高速输入命令的技巧. 在命令 ...

  8. Lucene学习总结之一:全文检索的基本原理 2014-06-25 14:11 666人阅读 评论(0) 收藏

    一.总论 根据http://lucene.apache.org/java/docs/index.html 定义: Lucene 是一个高效的,基于Java 的全文检索库. 所以在了解Lucene之前要 ...

  9. python opencv3 —— findContours

    findContours 是 opencv 下的轮廓提取函数. 1. api 分析 findContours(image, mode, method[, contours[, hierarchy[, ...

  10. 【30.49%】【codeforces 569A】Music

    time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...