博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
ZetCode PyQt4 tutorial widgets II
阅读量:7051 次
发布时间:2019-06-28

本文共 5455 字,大约阅读时间需要 18 分钟。

#!/usr/bin/python# -*- coding: utf-8 -*-"""ZetCode PyQt4 tutorial In this example, we dispay an imageon the window. author: Jan Bodnarwebsite: zetcode.com last edited: September 2011"""import sysfrom PyQt4 import QtGui, QtCoreclass Example(QtGui.QWidget):        def __init__(self):        super(Example, self).__init__()                self.initUI()            def initUI(self):              hbox = QtGui.QHBoxLayout(self)        # We create a QtGui.QPixmap object. It takes the name of the file as a parameter.        pixmap = QtGui.QPixmap("redrock.png")        lbl = QtGui.QLabel(self)        # We put the pixmap into the QtGui.QLabel widget.        lbl.setPixmap(pixmap)        hbox.addWidget(lbl)        self.setLayout(hbox)                self.move(300, 200)        self.setWindowTitle('Red Rock')        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 example shows text which is entered in a QtGui.QLineEditin a QtGui.QLabel widget. author: Jan Bodnarwebsite: zetcode.com last edited: August 2011"""import sysfrom PyQt4 import QtGui, QtCoreclass Example(QtGui.QWidget):        def __init__(self):        super(Example, self).__init__()                self.initUI()            def initUI(self):              self.lbl = QtGui.QLabel(self)        # The QtGui.QLineEdit widget is created.        qle = QtGui.QLineEdit(self)                qle.move(60, 100)        self.lbl.move(60, 40)        # If the text in the line edit widget changes, we call the onChanged() method.        qle.textChanged[str].connect(self.onChanged)                self.setGeometry(300, 300, 280, 170)        self.setWindowTitle('QtGui.QLineEdit')        self.show()            # Inside the onChanged() method, we set the typed text to the label widget. We call the adjustSize() method to adjust the size of the label to the length of the text.    def onChanged(self, text):                self.lbl.setText(text)        self.lbl.adjustSize()                        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 example showshow to use QtGui.QSplitter widget. author: Jan Bodnarwebsite: zetcode.com last edited: September 2011"""import sysfrom PyQt4 import QtGui, QtCoreclass Example(QtGui.QWidget):        def __init__(self):        super(Example, self).__init__()                self.initUI()            def initUI(self):              hbox = QtGui.QHBoxLayout(self)        # We use a styled frame in order to see the boundaries between the QtGui.QFrame widgets.        topleft = QtGui.QFrame(self)        topleft.setFrameShape(QtGui.QFrame.StyledPanel)         topright = QtGui.QFrame(self)        topright.setFrameShape(QtGui.QFrame.StyledPanel)        bottom = QtGui.QFrame(self)        bottom.setFrameShape(QtGui.QFrame.StyledPanel)        # We create a QtGui.QSplitter widget and add two frames into it.        splitter1 = QtGui.QSplitter(QtCore.Qt.Horizontal)        splitter1.addWidget(topleft)        splitter1.addWidget(topright)        # We can also add a splitter to another splitter widget.        splitter2 = QtGui.QSplitter(QtCore.Qt.Vertical)        splitter2.addWidget(splitter1)        splitter2.addWidget(bottom)        hbox.addWidget(splitter2)        self.setLayout(hbox)        QtGui.QApplication.setStyle(QtGui.QStyleFactory.create('Cleanlooks'))                self.setGeometry(300, 300, 300, 200)        self.setWindowTitle('QtGui.QSplitter')        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 example showshow to use QtGui.QComboBox widget. author: Jan Bodnarwebsite: zetcode.com last edited: September 2011"""import sysfrom PyQt4 import QtGui, QtCoreclass Example(QtGui.QWidget):        def __init__(self):        super(Example, self).__init__()                self.initUI()            def initUI(self):              self.lbl = QtGui.QLabel("Ubuntu", self)        # We create a QtGui.QComboBox widget with five options.        combo = QtGui.QComboBox(self)        combo.addItem("Ubuntu")        combo.addItem("Mandriva")        combo.addItem("Fedora")        combo.addItem("Red Hat")        combo.addItem("Gentoo")        combo.move(50, 50)        self.lbl.move(50, 150)        # Upon an item selection, we call the onActivated() method.        combo.activated[str].connect(self.onActivated)                         self.setGeometry(300, 300, 300, 200)        self.setWindowTitle('QtGui.QComboBox')        self.show()            # Inside the method, we set the text of the chosen item to the label widget. We adjust the size of the label.    def onActivated(self, text):              self.lbl.setText(text)        self.lbl.adjustSize()                  def main():        app = QtGui.QApplication(sys.argv)    ex = Example()    sys.exit(app.exec_())if __name__ == '__main__':    main()

 

转载地址:http://wzpol.baihongyu.com/

你可能感兴趣的文章
eclipse 自动创建web.xml
查看>>
十一.单表更新及多表更新
查看>>
32位64位操作系统基本数据类型字节大小
查看>>
linux高级编程day04 笔记
查看>>
BZOJ 1006: [HNOI2008]神奇的国度
查看>>
Django 安装
查看>>
Centos Git1.7.1升级到Git2.2.1
查看>>
算法题总结----数组(二分查找)
查看>>
OPENWRT make menuconfig错误之一
查看>>
可集成到APP的车架号识别软件
查看>>
导出查询结果到csv文件
查看>>
Algs4-2.3.19五取样切分
查看>>
IDEA常用快揵键
查看>>
git 学习笔记
查看>>
[HDU5968]异或密码
查看>>
Vue的安装
查看>>
iOS开发~CocoaPods使用详细说明
查看>>
C#扩展方法
查看>>
移动浏览器中实现拨打电话,调用sms,发送email
查看>>
docker 搭建小型的node开发环境。
查看>>