Import sysfrom pyqt5.qtwidgets import Qwidget, Qlabel, Qapplication, Qpushbutton, Qhboxlayout, Qvboxlayout, Qgridlayoutclass Example (qwidget): def __init__ (self): Super (). __init__ () Self.initui () #----------------- -----------------------------------------def initui (self): Grid = Qgridlayout () self.setlayout (GRID) names = [' C ', ' Bck ', ' Wang Xiaotao _ ', ' Learning ', ' 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 (self.setwindowtitle) (' Calculator ') self.show () #--------------------- ----------------------------------------if __name__ = = ' __main__ ': app = Qapplication (sys.argv) ex = Example () sys.exit ((App.exec_ ()))
Reprint please indicate the author and source: http://blog.csdn.net/u013511642 Wang Xiaotao _
PYQT5 Write a calculator frame