pyqt5 QPushButton()(使用clicked.connect())不起作用

时间:2017-11-08 20:31:38

标签: python qt pyqt pyqt5 qpushbutton

我有这个非常简单的GUI,但我无法按下按钮。我尝试在clicked.connect命令中使用部分 lambda ,但没有运气。我知道我只能按下按钮一次,因为我没有循环来改变每个新输入框的位置,但我只想让它先工作。

感谢您的任何建议

for file in $(find . -name '*.mp3') ; do
   base="${file%%.mp3}"
   cp "$base.jpg" "$base-poster.jpg"
   cp "$base.jpg" "$(dirname $base)/poster.jpg"
done

1 个答案:

答案 0 :(得分:0)

试试这个:

import sys
from PyQt5.QtWidgets import (QApplication, QWidget, QPushButton, QSizePolicy,
                         QDoubleSpinBox, QLabel, QCheckBox, QMainWindow,
QGridLayout)
from PyQt5.QtCore import QCoreApplication
import matplotlib
from matplotlib.figure import Figure
import numpy as np
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as NavigationToolbar



class MainWindow(QWidget):

    def __init__(self):
        super().__init__()

        self.initUI()

    def initUI(self):

        # Geometry of main window:
        self.setGeometry(200, 200, 1000, 1000)
        self.setWindowTitle('Simulation')

        #---------------------------------------
                # Button for adding blades
        blade_button = QPushButton('Add', self)
        blade_button.clicked.connect(self.add_Bladebox)
        blade_button.move(800, 600)


        #---------------------------------------

        self.show()

    # Method for input box:
    def inputBox(self, left, top, maxvalue, step, default,decimals):
        box = QDoubleSpinBox(self)
        box.move(left,top)
        box.setDecimals(decimals)
        box.setMaximum(maxvalue)
        box.setSingleStep(step)
        box.setProperty("value", default)
        box.resize(box.sizeHint())
        box.show()

    # Method for adding blade boxes
    def add_Bladebox(self):

        print('This is Ok')

        left = 900
        top = 500
        maxvalue = 3
        step = 1
        default = 0
        decimals = 1
        self.inputBox(left, top, maxvalue, step, default, decimals)


if __name__ == '__main__':

    app = QCoreApplication.instance()
    if app is None:
        app = QApplication(sys.argv)
    ex = MainWindow()
    sys.exit(app.exec_())