ZetCode PyQt4 tutorial layout management
!/usr/bin/python
-*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This example shows three labels on a window
using absolute positioning. author: Jan Bodnar
website: zetcode.com
last edited: October 2011
""" import sys
from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): # The label widget is positioned at x=15 and y=10.
lbl1 = QtGui.QLabel('ZetCode', self)
lbl1.move(15, 10) lbl2 = QtGui.QLabel('tutorials', self)
lbl2.move(35, 40) lbl3 = QtGui.QLabel('for programmers', self)
lbl3.move(55, 70) self.setGeometry(300, 300, 250, 150)
self.setWindowTitle('Absolute')
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 In this example, we position two push
buttons in the bottom-right corner
of the window. author: Jan Bodnar
website: zetcode.com
last edited: October 2011
""" import sys
from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): # Here we create two push buttons.
okButton = QtGui.QPushButton("OK")
cancelButton = QtGui.QPushButton("Cancel") # We create a horizontal box layout and add a stretch factor and both buttons. The stretch adds a stretchable space before the two buttons. This will push them to the right of the window.
hbox = QtGui.QHBoxLayout()
# Adds a stretchable space (a QSpacerItem) with zero minimum size and stretch factor stretch to the end of this box layout.
# 添加一个弹簧,填充空间
hbox.addStretch(1)
hbox.addWidget(okButton)
hbox.addWidget(cancelButton) # To create the necessary layout, we put a horizontal layout into a vertical one. The stretch factor in the vertical box will push the horizontal box with the buttons to the bottom of the window.
vbox = QtGui.QVBoxLayout()
# 添加一个弹簧,填充空间
vbox.addStretch(1)
vbox.addLayout(hbox) # Finally, we set the main layout of the window.
self.setLayout(vbox) self.setGeometry(300, 300, 300, 150)
self.setWindowTitle('Buttons')
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 -*- import sys
from PyQt4 import QtGui """
ZetCode PyQt4 tutorial In this example, we create a skeleton
of a calculator using a QtGui.QGridLayout. author: Jan Bodnar
website: zetcode.com
last edited: July 2014
""" class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): # The instance of a QtGui.QGridLayout is created and set to be the layout for the application window.
grid = QtGui.QGridLayout()
self.setLayout(grid) # These are the labels used later for buttons.
names = ['Cls', 'Bck', '', 'Close',
'', '', '', '/',
'', '', '', '*',
'', '', '', '-',
'', '.', '=', '+'] # We create a list of positions in the grid.
positions = [(i,j) for i in range(5) for j in range(4)] # Buttons are created and added to the layout with the addWidget() method.
for position, name in zip(positions, names): if name == '':
continue
button = QtGui.QPushButton(name)
grid.addWidget(button, *position) self.move(300, 150)
self.setWindowTitle('Calculator')
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 In this example, we create a bit
more complicated window layout using
the QtGui.QGridLayout manager. author: Jan Bodnar
website: zetcode.com
last edited: October 2011
""" import sys
from PyQt4 import QtGui class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): title = QtGui.QLabel('Title')
author = QtGui.QLabel('Author')
review = QtGui.QLabel('Review') titleEdit = QtGui.QLineEdit()
authorEdit = QtGui.QLineEdit()
reviewEdit = QtGui.QTextEdit() # We create a grid layout and set spacing between widgets.
grid = QtGui.QGridLayout()
grid.setSpacing(10) grid.addWidget(title, 1, 0)
grid.addWidget(titleEdit, 1, 1) grid.addWidget(author, 2, 0)
grid.addWidget(authorEdit, 2, 1) grid.addWidget(review, 3, 0)
# If we add a widget to a grid, we can provide row span and column span of the widget. In our case, we make the reviewEdit widget span 5 rows.
grid.addWidget(reviewEdit, 3, 1, 5, 1) self.setLayout(grid) self.setGeometry(300, 300, 350, 300)
self.setWindowTitle('Review')
self.show() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()
ZetCode PyQt4 tutorial layout management的更多相关文章
- 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 work with menus, toolbars, a statusbar, and a main application window
!/usr/bin/python -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial This program create ...
- 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, ...
随机推荐
- PAT 1143 Lowest Common Ancestor[难][BST性质]
1143 Lowest Common Ancestor(30 分) The lowest common ancestor (LCA) of two nodes U and V in a tree is ...
- Windows2003 + IIS6 安装.Net FrameWork 4.0 兼容早期版本的测试
看到文档说.net4的框架可以向下兼容2.0.3.0.3.5这几个版本,觉得是一件好事,以后服务器上就不用费时费力的安装 2.0.3.5之类的框架了.但是又觉得奇怪,2.0和3.5的框架都是很大的,为 ...
- python3 函数即变量的使用
函数即变量的意思是函数被使用时后面不用(),类似变量的使用,具体如下面的示例代码: def say(name): print(name) hi = say hi('你好!') def add(): p ...
- python16_day36【爬虫1】
一.requests 1. GET请求 # 1.无参数实例 import requests ret = requests.get('https://github.com/timeline.json') ...
- bootstrap fileinput api翻译笔记
bootstrap fileinput HTML标签属性 data-show-preview="false" // 是否显示预览区 multiple // 多文件 data-sho ...
- http之post和get请求的区别
GET请求 GET /books/?sex=man&name=Professional HTTP/1.1 Host: www.wrox.com User-Agent: Mozilla/5.0 ...
- 图解Kerberos认证工作原理
本文是我在看了这篇英文说明之后的总结 https://technet.microsoft.com/zh-cn/library/cc961976.aspx 是总结,不是翻译,所以是我看后按自己的理解写的 ...
- SQL group by的使用
①定义 "group by" 从字面上理解是根据“by"指定的规则对数据进行分组 ②简单示例 ③group by 中的select字段是受限制的 select指定的字段要 ...
- CentOS下 Nginx1.13.5 + PHP7.1.10 + MySQL5.7.19 源码编译安装
一.安装Nginx ①安装依赖扩展 # yum -y install wget openssl* gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng l ...
- 20145319 《网络对抗》逆向与Bof基础
20145319 逆向与Bof实验 1 实验内容 本次实验以可执行文件pwn1为例,将对pwn1进行反汇编的基础上进行功能上的解读,并进行缓冲区溢出攻击 可执行文件pwn1的正常流程是主函数调用foo ...