pyqt学习笔记

每日学习3_pyqt_界面布局学习

2018-01-24  本文已影响29人  Symbian米汤

每天都要有收获

布局管理:

  界面代码
# -*- coding: utf-8 -*-

# Form implementation generated from reading ui file 'designer_1.ui'
#
# Created by: PyQt5 UI code generator 5.9.2
#
# WARNING! All changes made in this file will be lost!

from PyQt5 import QtCore, QtGui, QtWidgets

class Ui_MainWindow(object):
    def setupUi(self, MainWindow):
        MainWindow.setObjectName("MainWindow")
        MainWindow.resize(657, 472)
        MainWindow.setStyleSheet("color: rgb(0, 170, 255);")
        self.centralwidget = QtWidgets.QWidget(MainWindow)
        self.centralwidget.setObjectName("centralwidget")
        self.pushButton = QtWidgets.QPushButton(self.centralwidget)
        self.pushButton.setGeometry(QtCore.QRect(314, 114, 75, 23))
        self.pushButton.setStyleSheet("font: 9pt \"幼圆\";")
        self.pushButton.setObjectName("pushButton")
        self.label_3 = QtWidgets.QLabel(self.centralwidget)
        self.label_3.setGeometry(QtCore.QRect(50, 90, 24, 16))
        self.label_3.setObjectName("label_3")
        self.label_4 = QtWidgets.QLabel(self.centralwidget)
        self.label_4.setGeometry(QtCore.QRect(40, 120, 48, 16))
        self.label_4.setObjectName("label_4")
        self.label_5 = QtWidgets.QLabel(self.centralwidget)
        self.label_5.setGeometry(QtCore.QRect(40, 140, 42, 16))
        self.label_5.setObjectName("label_5")
        self.line_2 = QtWidgets.QFrame(self.centralwidget)
        self.line_2.setGeometry(QtCore.QRect(259, 71, 16, 110))
        self.line_2.setFrameShape(QtWidgets.QFrame.VLine)
        self.line_2.setFrameShadow(QtWidgets.QFrame.Sunken)
        self.line_2.setObjectName("line_2")
        self.widget = QtWidgets.QWidget(self.centralwidget)
        self.widget.setGeometry(QtCore.QRect(133, 71, 120, 86))
        self.widget.setObjectName("widget")
        self.gridLayout = QtWidgets.QGridLayout(self.widget)
        self.gridLayout.setContentsMargins(0, 0, 0, 0)
        self.gridLayout.setObjectName("gridLayout")
        self.maxdown_min = QtWidgets.QDoubleSpinBox(self.widget)
        self.maxdown_min.setObjectName("maxdown_min")
        self.gridLayout.addWidget(self.maxdown_min, 2, 0, 1, 1)
        self.return_max = QtWidgets.QDoubleSpinBox(self.widget)
        self.return_max.setObjectName("return_max")
        self.gridLayout.addWidget(self.return_max, 1, 1, 1, 1)
        self.label = QtWidgets.QLabel(self.widget)
        self.label.setObjectName("label")
        self.gridLayout.addWidget(self.label, 0, 0, 1, 1)
        self.label_2 = QtWidgets.QLabel(self.widget)
        self.label_2.setObjectName("label_2")
        self.gridLayout.addWidget(self.label_2, 0, 1, 1, 1)
        self.maxdown_max = QtWidgets.QDoubleSpinBox(self.widget)
        self.maxdown_max.setObjectName("maxdown_max")
        self.gridLayout.addWidget(self.maxdown_max, 2, 1, 1, 1)
        self.sharp_min = QtWidgets.QDoubleSpinBox(self.widget)
        self.sharp_min.setObjectName("sharp_min")
        self.gridLayout.addWidget(self.sharp_min, 3, 0, 1, 1)
        self.sharp_max = QtWidgets.QDoubleSpinBox(self.widget)
        self.sharp_max.setObjectName("sharp_max")
        self.gridLayout.addWidget(self.sharp_max, 3, 1, 1, 1)
        self.return_min = QtWidgets.QDoubleSpinBox(self.widget)
        self.return_min.setObjectName("return_min")
        self.gridLayout.addWidget(self.return_min, 1, 0, 1, 1)
        MainWindow.setCentralWidget(self.centralwidget)
        self.menubar = QtWidgets.QMenuBar(MainWindow)
        self.menubar.setGeometry(QtCore.QRect(0, 0, 657, 23))
        self.menubar.setObjectName("menubar")
        MainWindow.setMenuBar(self.menubar)
        self.statusbar = QtWidgets.QStatusBar(MainWindow)
        self.statusbar.setObjectName("statusbar")
        MainWindow.setStatusBar(self.statusbar)
        self.label_3.setBuddy(self.return_min)
        self.label_4.setBuddy(self.maxdown_min)
        self.label_5.setBuddy(self.sharp_min)

        self.retranslateUi(MainWindow)
        self.pushButton.clicked.connect(MainWindow.onPushButton_clicked)
        QtCore.QMetaObject.connectSlotsByName(MainWindow)

    def retranslateUi(self, MainWindow):
        _translate = QtCore.QCoreApplication.translate
        MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
        self.pushButton.setText(_translate("MainWindow", "开始"))
        self.label_3.setText(_translate("MainWindow", "收益"))
        self.label_4.setText(_translate("MainWindow", "最大回撤"))
        self.label_5.setText(_translate("MainWindow", "sharp比"))
        self.label.setText(_translate("MainWindow", "最小值"))
        self.label_2.setText(_translate("MainWindow", "最大值"))
运行代码
# -*- coding: utf-8 -*-
# @Time    : 2018/1/24 0:36
# @Author  : houyujiang
# @Email   : houyujiang@live.cn
# @File    : designer1_run.py
# @Software: PyCharm
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QMainWindow,QApplication
from designer_1 import Ui_MainWindow

class LayoutDemo(QMainWindow,Ui_MainWindow):
    def __init__(self,parent = None):
        super(LayoutDemo,self).__init__(parent)
        self.setupUi(self)
    def onPushButton_clicked(self):
        print('收益_min:',self.return_min.text())
        print('收益_max:',self.return_max.text())
        print('最大回撤_min:', self.maxdown_min.text())
        print('最大回撤_max:', self.maxdown_max.text())
        print('sharp比_min:', self.sharp_min.text())
        print('sharp比_max:', self.sharp_max.text())
if __name__ == '__main__':
    import sys
    app = QApplication(sys.argv)
    ui = LayoutDemo()
    ui.show()
    sys.exit(app.exec_())


run.png
上一篇下一篇

猜你喜欢

热点阅读