首页 > 其他 > 详细

PyQt5 写一个计算器框架

时间:2015-05-02 09:48:26      阅读:216      评论:0      收藏:0      [点我收藏+]
import sys
from PyQt5.QtWidgets import QWidget, QLabel, QApplication, QPushButton, QHBoxLayout, QVBoxLayout, QGridLayout
class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
#----------------------------------------------------------

    def initUI(self):
        grid = QGridLayout()
        self.setLayout(grid)
        names = ['C', 'Bck', '王小涛_', '同學',
                 '7', '8', '9', '/',
                '4', '5', '6', '*',
                 '1', '2', '3', '-',
                 '0', '.', '=', '+']
        positions = [(i, j) for i in range(5) for j in range(4)]
        for position, name in zip(positions, names):
            if name == '':
                continue
            button = QPushButton(name)
            grid.addWidget(button, *position)


#------------------------------------------------------------
        self.setGeometry(300, 300, 300, 150)
        self.setWindowTitle('计算器')
        self.show()
#-------------------------------------------------------------
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit((app.exec_()))
技术分享

转载请注明作者与出处:http://blog.csdn.net/u013511642  王小涛_同學


PyQt5 写一个计算器框架

原文:http://blog.csdn.net/u013511642/article/details/45420849

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!