ZetCode PyQt4 tutorial work with menus, toolbars, a statusbar, and a main application window
- !/usr/bin/python
- -*- coding: utf-8 -*-
- """
- ZetCode PyQt4 tutorial
- This program creates a statusbar.
- author: Jan Bodnar
- website: zetcode.com
- last edited: September 2011
- """
- import sys
- from PyQt4 import QtGui
- class Example(QtGui.QMainWindow):
- def __init__(self):
- # super(type[, object-or-type]): Return a proxy object that delegates method calls to a parent or sibling class of type.
- super(Example, self).__init__()
- self.initUI()
- def initUI(self):
- # To get the statusbar, we call the statusBar() method of the QtGui.QMainWindow class. The first call of the method creates a status bar. Subsequent calls return the statusbar object. The showMessage() displays a message on the statusbar.
- self.statusBar().showMessage('Ready')
- self.setGeometry(300, 300, 250, 150)
- self.setWindowTitle('Statusbar')
- self.show()
- def main():
- app = QtGui.QApplication(sys.argv)
- ex = Example()
- sys.exit(app.exec_())
- if __name__ == '__main__':
- main()
- --------------------------------------------------------------------------------
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- """
- ZetCode PyQt4 tutorial
- This program creates a menubar. The
- menubar has one menu with an exit action.
- author: Jan Bodnar
- website: zetcode.com
- last edited: August 2011
- """
- import sys
- from PyQt4 import QtGui
- class Example(QtGui.QMainWindow):
- def __init__(self):
- super(Example, self).__init__()
- self.initUI()
- def initUI(self):
- # A QtGui.QAction is an abstraction for actions performed with a menubar, toolbar or with a custom keyboard shortcut. In the above three lines, we create an action with a specific icon and an 'Exit' label. Furthermore, a shortcut is defined for this action. The third line creates a status tip which is shown in the statusbar when we hover a mouse pointer over the menu item.
- exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Exit', self)
- exitAction.setShortcut('Ctrl+Q')
- exitAction.setStatusTip('Exit application')
- # When we select this particular action, a triggered signal is emitted. The signal is connected to the quit() method of the QtGui.QApplication widget. This terminates the application.
- exitAction.triggered.connect(QtGui.qApp.quit)
- self.statusBar()
- # The menuBar() method creates a menubar. We create a file menu and append the exit action to it.
- menubar = self.menuBar()
- fileMenu = menubar.addMenu('&File')
- fileMenu.addAction(exitAction)
- self.setGeometry(300, 300, 300, 200)
- self.setWindowTitle('Menubar')
- self.show()
- def main():
- app = QtGui.QApplication(sys.argv)
- ex = Example()
- sys.exit(app.exec_())
- if __name__ == '__main__':
- main()
- -------------------------------------------------------------------------------
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- """
- ZetCode PyQt4 tutorial
- This program creates a toolbar.
- The toolbar has one action, which
- terminates the application if triggered.
- author: Jan Bodnar
- website: zetcode.com
- last edited: September 2011
- """
- import sys
- from PyQt4 import QtGui
- class Example(QtGui.QMainWindow):
- def __init__(self):
- super(Example, self).__init__()
- self.initUI()
- def initUI(self):
- # Similar to the menubar example above, we create an action object. The object has a label, icon and a shorcut. A quit() method of the QtGui.QMainWindow is connected to the triggered signal.
- exitAction = QtGui.QAction(QtGui.QIcon('exit24.png'), 'Exit', self)
- exitAction.setShortcut('Ctrl+Q')
- exitAction.triggered.connect(QtGui.qApp.quit)
- # Here we create a toolbar and plug and action object into it.
- self.toolbar = self.addToolBar('Exit')
- self.toolbar.addAction(exitAction)
- self.setGeometry(300, 300, 300, 200)
- self.setWindowTitle('Toolbar')
- self.show()
- def main():
- app = QtGui.QApplication(sys.argv)
- ex = Example()
- sys.exit(app.exec_())
- if __name__ == '__main__':
- main()
- --------------------------------------------------------------------------------
- #!/usr/bin/python
- # -*- coding: utf-8 -*-
- """
- ZetCode PyQt4 tutorial
- This program creates a skeleton of
- a classic GUI application with a menubar,
- toolbar, statusbar and a central widget.
- author: Jan Bodnar
- website: zetcode.com
- last edited: September 2011
- """
- import sys
- from PyQt4 import QtGui
- class Example(QtGui.QMainWindow):
- def __init__(self):
- super(Example, self).__init__()
- self.initUI()
- def initUI(self):
- # Here we create a text edit widget. We set it to be the central widget of the QtGui.QMainWindow. The central widget occupies all space that is left.
- textEdit = QtGui.QTextEdit()
- self.setCentralWidget(textEdit)
- exitAction = QtGui.QAction(QtGui.QIcon('exit24.png'), 'Exit', self)
- exitAction.setShortcut('Ctrl+Q')
- exitAction.setStatusTip('Exit application')
- exitAction.triggered.connect(self.close)
- self.statusBar()
- menubar = self.menuBar()
- fileMenu = menubar.addMenu('&File')
- fileMenu.addAction(exitAction)
- toolbar = self.addToolBar('Exit')
- toolbar.addAction(exitAction)
- self.setGeometry(300, 300, 350, 250)
- self.setWindowTitle('Main window')
- self.show()
- def main():
- app = QtGui.QApplication(sys.argv)
- ex = Example()
- sys.exit(app.exec_())
- if __name__ == '__main__':
- main()
ZetCode PyQt4 tutorial work with menus, toolbars, a statusbar, and a main application window的更多相关文章
- ZetCode PyQt4 tutorial Drag and Drop
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This is a simple ...
- ZetCode PyQt4 tutorial widgets II
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial widgets I
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial Dialogs
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial signals and slots
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial layout management
!/usr/bin/python -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This example shows ...
- ZetCode PyQt4 tutorial First programs
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial custom widget
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
- ZetCode PyQt4 tutorial basic painting
#!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...
随机推荐
- kindle 应用程序出错,无法启动选定的应用程序,请重试。问题排查过程及处理方案。
最近一段时间在使用Kindle商城时总是会出现“应用程序出错,无法启动选定的应用程序,请重试.” 对此我花了大约一小时的时间进行测试验证并与客服人员沟通,将过程记录如下,供出现同样问题的朋友们参考. ...
- 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution
A:Alphabet Solved. 签. #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ scanf(); ...
- python 字节字符串上的字符串操作
问题:想在字节字符串上执行普通的文本操作(比如移除,搜索和替换). 解决方案 1)字节字符串同样也支持大部分和文本字符串一样的内置操作.比如: >>> data = b'Hello ...
- CF337C - Quiz
/*题目大意,给出n道题,假设答对了m道题,求最小的分数,有一个规则,就是连续答对num==k道题那么分数就翻倍,然后num清零,从新开始计数,到大连续k道的时候 要先加上这道题的分数1,再乘以2, ...
- SQL学习笔记四(补充-2-1)之MySQL SQL查询作业答案
阅读目录 一 题目 二 答案 一 题目 1.查询所有的课程的名称以及对应的任课老师姓名 2.查询学生表中男女生各有多少人 3.查询物理成绩等于100的学生的姓名 4.查询平均成绩大于八十分的同学的姓名 ...
- pip安装tensorflow-gpu好慢怎么办
答:为pip换源,如换成清华源 cat ~/.pip/pip.conf(没有此文件,自行创建即可,然后加入以下内容) [global]index-url = https://pypi.tuna.tsi ...
- String StringBuilder StringBuffer 对比 总结得非常好
转自:http://www.iteye.com/topic/522167 作者:每次上网冲杯Java时,都能看到关于String无休无止的争论.还是觉得有必要让这个讨厌又很可爱的String美眉,赤裸 ...
- Object.defineProperty和Object.defineProperties
添加属性到对象,或修改现有属性的特性 用法: Object.defineProperty(object, propertyName, descriptor); 参数: object ...
- Linux清除Windows密码
下载安装ntfs-3g 下载驱动让linux挂载windows磁盘 https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2017.3.23.tgz 安装 t ...
- 分布式缓存--系列1 -- Hash环/一致性Hash原理
当前,Memcached.Redis这类分布式kv缓存已经非常普遍.从本篇开始,本系列将分析分布式缓存相关的原理.使用策略和最佳实践. 我们知道Memcached的分布式其实是一种“伪分布式”,也就是 ...