import sys
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QMainWindow, QMenuBar, QToolBar, QTextEdit, QAction, QApplication, qApp, QMessageBox
from PyQt5.QtCore import Qt import threading
import time songs = ['爱情买卖','朋友','回家过年','好日子']
films = ['阿凡达','猩球崛起'] class MyWindow(QMainWindow):
def __init__(self):
super().__init__() self.resize(677, 442)
self.setWindowTitle("我的程序") self.createUI()
self.createAction()
self.createStatusbar()
self.createMenu()
self.createToolbar() def createUI(self):
self.textedit = QTextEdit()
self.setCentralWidget(self.textedit) # 动作
def createAction(self):
self.exit_action = QAction(QIcon("ico_new.jpg"), "退出", self, triggered=qApp.quit)
self.exit_action.setStatusTip("退出程序")
self.exit_action.setShortcut("Ctrl+Q")
self.exit_action.triggered.connect(qApp.quit) # 状态栏
def createStatusbar(self):
self.statusBar() # 菜单栏
def createMenu(self):
#menubar = QMenuBar(self)
menubar = self.menuBar()
menu = menubar.addMenu("文件(F)")
menu.addAction(QAction(QIcon("ico_new_16_16.jpg"), "新建", self, triggered=qApp.quit)) # 带图标,文字
menu.addAction(QAction(QIcon("ico_open_16_16.jpg"), "打开", self, triggered=qApp.quit))
menu.addAction(QAction(QIcon("ico_save_16_16.jpg"), "保存", self, triggered=qApp.quit))
menu.addSeparator()
menu.addAction(QAction(QIcon("ico_close_16_16.jpg"), "关闭", self, triggered=lambda :QMessageBox.about(self, '关闭','关闭。。。'))) menu = menubar.addMenu("编辑(E)")
menu.addAction(QAction("撤销", self, triggered=qApp.quit)) # 不带图标
menu.addAction(QAction("剪切", self, triggered=qApp.quit))
menu.addAction(QAction("复制", self, triggered=qApp.quit))
menu.addAction(QAction("粘贴", self, triggered=qApp.quit)) menu = menubar.addMenu("娱乐(S)")
menu.addAction(QAction("音乐", self, triggered=lambda :self.thread_it(self.music, songs))) # 线程
menu.addAction(QAction("电影", self, triggered=lambda :self.thread_it(self.movie, films))) menu = menubar.addMenu("帮助(H)")
menu.addAction('&New', lambda :QMessageBox.about(self, 'New','新建。。。'), Qt.CTRL + Qt.Key_N) # 注意快捷键
menu.addAction('关于', lambda :QMessageBox.about(self, '关于','关于。。。'), Qt.CTRL + Qt.Key_Q) # 工具栏
def createToolbar(self):
toolbar = self.addToolBar('文件')
toolbar.addAction(QAction(QIcon("ico_new_16_16.jpg"), "新建", self, triggered=qApp.quit)) # 带图标,文字
toolbar.addAction(QAction(QIcon("ico_open_16_16.jpg"), "打开", self, triggered=qApp.quit))
toolbar.addSeparator()
toolbar.addAction(QAction(QIcon("ico_save_16_16.jpg"), "打开", self, triggered=qApp.quit)) toolbar = self.addToolBar("编辑")
toolbar.addAction(QAction("撤销", self, triggered=qApp.quit)) # 不带图标
toolbar.addAction(QAction("剪切", self, triggered=qApp.quit)) # 逻辑:听音乐
def music(self, songs):
for x in songs:
self.textedit.append("听音乐:%s \t-- %s" %(x, time.ctime()))
time.sleep(3) # 逻辑:看电影
def movie(self, films):
for x in films:
self.textedit.append("看电影:%s \t-- %s" %(x, time.ctime()))
time.sleep(5) # 打包进线程(耗时的操作)
@staticmethod
def thread_it(func, *args):
t = threading.Thread(target=func, args=args)
t.setDaemon(True) # 守护--就算主界面关闭,线程也会留守后台运行(不对!)
t.start() # 启动
# t.join() # 阻塞--会卡死界面! app = QApplication(sys.argv)
win = MyWindow()
win.show()
sys.exit(app.exec_())

pyqt5 菜单,工具栏,线程,matplotlib的更多相关文章

  1. 基于 SailingEase WinForm Framework 开发客户端程序(3:实现菜单/工具栏按钮的解耦及状态控制)

    本系列文章将详细阐述客户端应用程序的设计理念,实现方法. 本系列文章以  SailingEase WinForm Framework 为基础进行设计并实现,但其中的设计理念及方法,亦适用于任何类型的客 ...

  2. 菜单工具栏wxPython菜单与工具栏基础示例

    这两天一直在学习菜单工具栏之类的问题,上午正好有机会和大家讨论一下. 1.基本的api介绍 Package wx :: Class Menu Type Menu Method Summary Menu ...

  3. Python+PyQT5的子线程更新UI界面的实例《新手必学》

    今天小编就为大家分享一篇Python+PyQT5的子线程更新UI界面的实例,具有很好的参考价值,希望对大家有所帮助.一起跟随小编过来看看吧子线程里是不能更新UI界面的,在移动端方面.Android的U ...

  4. pyqt5 -——菜单和工具栏

    一. 状态栏 # -*- coding: utf-8 -*-# @Time : 2018/12/22 12:37# @Author : Bo# @Email : mat_wu@163.com# @Fi ...

  5. PyQt5 QSerialPort子线程操作

    环境: python3.6 pyqt5 只是简单的一个思路,请忽略脆弱的异常防护: # -*- coding: utf-8 -*- import sys from PyQt5.QtWidgets im ...

  6. WindowsForm菜单工具栏--2016年12月6日

    ContextMenuStrip 添加控件后可在其他空间属性中进行绑定 MenuStrip       设置热键:在编辑的时候输入(&F)       设置快捷键:选中菜单项--右键属性--S ...

  7. 菜单 & 工具栏 & 状态栏

    MFC中ON_UPDATE_COMMAND_UI和ON_COMMAND消息区别 CCmdUI 加载状态栏 加载工具栏

  8. pyqt5 重启相同线程错误:QThread: Destroyed while thread is still running

    背景: 把一个基于QObject的类的槽运行在另一个线程,我们可以用moveToThread的方法. 1 新建一个子线程类,编写槽函数和信号,MyClass *m_MyClass=new MyClas ...

  9. PyQt 5菜单和工具栏

    QMainWindow类提供主要应用程序的窗口,有添加状态栏.工具栏.菜单栏等功能 状态栏 self.statusBar().showMessage('Ready') # 创建一个状态栏 # 状态栏显 ...

随机推荐

  1. 【[SHOI2012]随机树】

    感觉第一问就非常神仙,还有第二问怎么被我当成组合数学题来做了 首先是第一问 期望具有线性性,于是深度平均值的期望等于深度和的期望值的平均 设\(dp_x\)表示具有\(x\)个叶子节点的树的深度和的期 ...

  2. Cookies、sessionStorage和localStorage解释及区别?

    浏览器的缓存机制提供了可以将用户数据存储在客户端上的方式,可以利用cookie,session等跟服务器端进行数据交互 一.cookie和session Cookie和 session都是用来跟踪浏览 ...

  3. [转].NET设计模式系列文章

    最初写探索设计模式系列的时候,我只是想把它作为自己学习设计模式的读书笔记来写,可是写到今天,设计模式带给我的震撼,以及许多初学者朋友的热心支持,让我下定决心要把这个系列写完写好,那怕花上再多的时间也无 ...

  4. sofar:机器学习检测十题

    http://sofasofa.io/forum_main_post.php?postid=1001084 http://sofasofa.io/forum_main_post.php?postid= ...

  5. CS20Chapter3

    waiting  P54 shuffle data 03_Lecture note_Linear and Logistic Regression 学习点1: python的地址输入是要不能用正斜杠\的 ...

  6. vim使用四个空格代替TAB键

    让VIM可以在你写程序的时候自动缩进,并用4个空格代替TAB键. 编辑 ~/.vimrc 保存这四行: “set smartindent”, “set tabstop=4”, “set shiftwi ...

  7. 【luogu P2827 蚯蚓】 题解

    题目链接:https://www.luogu.org/problemnew/show/P2827 35分:暴力sortO(mnlogn). 80分:考虑到每次不好维护不被切的点+q,正难则反.改成维护 ...

  8. Android App的签名打包(晋级篇)

    http://blog.csdn.net/linghu_java/article/details/6701666 Andriod应用程序如果要在手机或模拟器上安装,必须要有签名! 1.签名的意义 为了 ...

  9. 基于maven的JavaWeb项目构建部署

    需要准备的安装文件: 1 JDk http://www.oracle.com/technetwork/java/javase/downloads/index-jsp-138363.html jdk-8 ...

  10. 查看mysql中所有表的数据记录

    select table_name,table_rows from tables where TABLE_SCHEMA = 'database name' order by table_rows de ...