1. !/usr/bin/python
  2. -*- coding: utf-8 -*-
  3.  
  4. """
  5. ZetCode PyQt4 tutorial
  6.  
  7. This program creates a statusbar.
  8.  
  9. author: Jan Bodnar
  10. website: zetcode.com
  11. last edited: September 2011
  12. """
  13.  
  14. import sys
  15. from PyQt4 import QtGui
  16.  
  17. class Example(QtGui.QMainWindow):
  18.  
  19. def __init__(self):
  20. # super(type[, object-or-type]): Return a proxy object that delegates method calls to a parent or sibling class of type.
  21. super(Example, self).__init__()
  22.  
  23. self.initUI()
  24.  
  25. def initUI(self):
  26.  
  27. # 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.
  28. self.statusBar().showMessage('Ready')
  29.  
  30. self.setGeometry(300, 300, 250, 150)
  31. self.setWindowTitle('Statusbar')
  32. self.show()
  33.  
  34. def main():
  35.  
  36. app = QtGui.QApplication(sys.argv)
  37. ex = Example()
  38. sys.exit(app.exec_())
  39.  
  40. if __name__ == '__main__':
  41. main()
  42.  
  43. --------------------------------------------------------------------------------
  44.  
  45. #!/usr/bin/python
  46. # -*- coding: utf-8 -*-
  47.  
  48. """
  49. ZetCode PyQt4 tutorial
  50.  
  51. This program creates a menubar. The
  52. menubar has one menu with an exit action.
  53.  
  54. author: Jan Bodnar
  55. website: zetcode.com
  56. last edited: August 2011
  57. """
  58.  
  59. import sys
  60. from PyQt4 import QtGui
  61.  
  62. class Example(QtGui.QMainWindow):
  63.  
  64. def __init__(self):
  65. super(Example, self).__init__()
  66.  
  67. self.initUI()
  68.  
  69. def initUI(self):
  70.  
  71. # 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.
  72. exitAction = QtGui.QAction(QtGui.QIcon('exit.png'), '&Exit', self)
  73. exitAction.setShortcut('Ctrl+Q')
  74. exitAction.setStatusTip('Exit application')
  75. # 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.
  76. exitAction.triggered.connect(QtGui.qApp.quit)
  77.  
  78. self.statusBar()
  79.  
  80. # The menuBar() method creates a menubar. We create a file menu and append the exit action to it.
  81. menubar = self.menuBar()
  82. fileMenu = menubar.addMenu('&File')
  83. fileMenu.addAction(exitAction)
  84.  
  85. self.setGeometry(300, 300, 300, 200)
  86. self.setWindowTitle('Menubar')
  87. self.show()
  88.  
  89. def main():
  90.  
  91. app = QtGui.QApplication(sys.argv)
  92. ex = Example()
  93. sys.exit(app.exec_())
  94.  
  95. if __name__ == '__main__':
  96. main()
  97.  
  98. -------------------------------------------------------------------------------
  99.  
  100. #!/usr/bin/python
  101. # -*- coding: utf-8 -*-
  102.  
  103. """
  104. ZetCode PyQt4 tutorial
  105.  
  106. This program creates a toolbar.
  107. The toolbar has one action, which
  108. terminates the application if triggered.
  109.  
  110. author: Jan Bodnar
  111. website: zetcode.com
  112. last edited: September 2011
  113. """
  114.  
  115. import sys
  116. from PyQt4 import QtGui
  117.  
  118. class Example(QtGui.QMainWindow):
  119.  
  120. def __init__(self):
  121. super(Example, self).__init__()
  122.  
  123. self.initUI()
  124.  
  125. def initUI(self):
  126.  
  127. # 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.
  128. exitAction = QtGui.QAction(QtGui.QIcon('exit24.png'), 'Exit', self)
  129. exitAction.setShortcut('Ctrl+Q')
  130. exitAction.triggered.connect(QtGui.qApp.quit)
  131.  
  132. # Here we create a toolbar and plug and action object into it.
  133. self.toolbar = self.addToolBar('Exit')
  134. self.toolbar.addAction(exitAction)
  135.  
  136. self.setGeometry(300, 300, 300, 200)
  137. self.setWindowTitle('Toolbar')
  138. self.show()
  139.  
  140. def main():
  141.  
  142. app = QtGui.QApplication(sys.argv)
  143. ex = Example()
  144. sys.exit(app.exec_())
  145.  
  146. if __name__ == '__main__':
  147. main()
  148.  
  149. --------------------------------------------------------------------------------
  150.  
  151. #!/usr/bin/python
  152. # -*- coding: utf-8 -*-
  153.  
  154. """
  155. ZetCode PyQt4 tutorial
  156.  
  157. This program creates a skeleton of
  158. a classic GUI application with a menubar,
  159. toolbar, statusbar and a central widget.
  160.  
  161. author: Jan Bodnar
  162. website: zetcode.com
  163. last edited: September 2011
  164. """
  165.  
  166. import sys
  167. from PyQt4 import QtGui
  168.  
  169. class Example(QtGui.QMainWindow):
  170.  
  171. def __init__(self):
  172. super(Example, self).__init__()
  173.  
  174. self.initUI()
  175.  
  176. def initUI(self):
  177.  
  178. # 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.
  179. textEdit = QtGui.QTextEdit()
  180. self.setCentralWidget(textEdit)
  181.  
  182. exitAction = QtGui.QAction(QtGui.QIcon('exit24.png'), 'Exit', self)
  183. exitAction.setShortcut('Ctrl+Q')
  184. exitAction.setStatusTip('Exit application')
  185. exitAction.triggered.connect(self.close)
  186.  
  187. self.statusBar()
  188.  
  189. menubar = self.menuBar()
  190. fileMenu = menubar.addMenu('&File')
  191. fileMenu.addAction(exitAction)
  192.  
  193. toolbar = self.addToolBar('Exit')
  194. toolbar.addAction(exitAction)
  195.  
  196. self.setGeometry(300, 300, 350, 250)
  197. self.setWindowTitle('Main window')
  198. self.show()
  199.  
  200. def main():
  201.  
  202. app = QtGui.QApplication(sys.argv)
  203. ex = Example()
  204. sys.exit(app.exec_())
  205.  
  206. if __name__ == '__main__':
  207. main()

ZetCode PyQt4 tutorial work with menus, toolbars, a statusbar, and a main application window的更多相关文章

  1. ZetCode PyQt4 tutorial Drag and Drop

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This is a simple ...

  2. ZetCode PyQt4 tutorial widgets II

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  3. ZetCode PyQt4 tutorial widgets I

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  4. ZetCode PyQt4 tutorial Dialogs

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  5. ZetCode PyQt4 tutorial signals and slots

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  6. ZetCode PyQt4 tutorial layout management

    !/usr/bin/python -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This example shows ...

  7. ZetCode PyQt4 tutorial First programs

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  8. ZetCode PyQt4 tutorial custom widget

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

  9. ZetCode PyQt4 tutorial basic painting

    #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, ...

随机推荐

  1. kindle 应用程序出错,无法启动选定的应用程序,请重试。问题排查过程及处理方案。

    最近一段时间在使用Kindle商城时总是会出现“应用程序出错,无法启动选定的应用程序,请重试.” 对此我花了大约一小时的时间进行测试验证并与客服人员沟通,将过程记录如下,供出现同样问题的朋友们参考. ...

  2. 2016-2017 ACM-ICPC Pacific Northwest Regional Contest (Div. 1) Solution

    A:Alphabet Solved. 签. #include<bits/stdc++.h> using namespace std; ]; ]; int main(){ scanf(); ...

  3. python 字节字符串上的字符串操作

    问题:想在字节字符串上执行普通的文本操作(比如移除,搜索和替换). 解决方案 1)字节字符串同样也支持大部分和文本字符串一样的内置操作.比如: >>> data = b'Hello ...

  4. CF337C - Quiz

    /*题目大意,给出n道题,假设答对了m道题,求最小的分数,有一个规则,就是连续答对num==k道题那么分数就翻倍,然后num清零,从新开始计数,到大连续k道的时候 要先加上这道题的分数1,再乘以2, ...

  5. SQL学习笔记四(补充-2-1)之MySQL SQL查询作业答案

    阅读目录 一 题目 二 答案 一 题目 1.查询所有的课程的名称以及对应的任课老师姓名 2.查询学生表中男女生各有多少人 3.查询物理成绩等于100的学生的姓名 4.查询平均成绩大于八十分的同学的姓名 ...

  6. pip安装tensorflow-gpu好慢怎么办

    答:为pip换源,如换成清华源 cat ~/.pip/pip.conf(没有此文件,自行创建即可,然后加入以下内容) [global]index-url = https://pypi.tuna.tsi ...

  7. String StringBuilder StringBuffer 对比 总结得非常好

    转自:http://www.iteye.com/topic/522167 作者:每次上网冲杯Java时,都能看到关于String无休无止的争论.还是觉得有必要让这个讨厌又很可爱的String美眉,赤裸 ...

  8. Object.defineProperty和Object.defineProperties

    添加属性到对象,或修改现有属性的特性   用法:     Object.defineProperty(object, propertyName, descriptor); 参数:     object ...

  9. Linux清除Windows密码

    下载安装ntfs-3g 下载驱动让linux挂载windows磁盘 https://tuxera.com/opensource/ntfs-3g_ntfsprogs-2017.3.23.tgz 安装 t ...

  10. 分布式缓存--系列1 -- Hash环/一致性Hash原理

    当前,Memcached.Redis这类分布式kv缓存已经非常普遍.从本篇开始,本系列将分析分布式缓存相关的原理.使用策略和最佳实践. 我们知道Memcached的分布式其实是一种“伪分布式”,也就是 ...