pyqt5 QpushButton无法正常工作

时间:2017-11-08 08:20:06

标签: python user-interface pyqt qpushbutton

我有这个用python编写的GUI并使用PYQT5。我有一个正常运行的版本,但我现在想添加一个执行名为add_Bladebox的方法的QpushButton。这个方法为gui添加了一个双打盒子。当我将它作为代码的一部分调用时,该方法工作正常,但是当我尝试通过QpushButton执行它时,没有任何反应。我知道没有循环,我只能做一次(没有实现位置更改),但我可以稍后添加该功能。因此,任何关于它为什么不起作用的建议都会受到好评。

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

# Mark: QGridlayout importoitu, muttei käytetty

from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as F 
igureCanvas
from matplotlib.backends.backend_qt5agg import NavigationToolbar2QT as 
NavigationToolbar


class MainWindow(QWidget):

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

    self.initUI()

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


    # Set canvas:   
    self.m = PlotCanvas(self, width=5, height=10)
    self.m.move(0,0)


    # Simulate button:
    sim = QPushButton('Simulate', self)
    sim.clicked.connect(self.simulate)
    sim.resize(sim.sizeHint())
    sim.move(550, 700)

    # Quit button:
    qbtn = QPushButton('Quit', self)
    qbtn.clicked.connect(QCoreApplication.instance().quit)
    qbtn.resize(qbtn.sizeHint())
    qbtn.move(800, 700)

    # Input box for x1:
    self.x1 = self.inputBox(800,80,10.0,0.01,0.2,2)
    self.x1_label = self.label(800,60,"x1")


    # Checkbox for sending data via email:
    self.send_box = QCheckBox('Send data’, self)
    self.send_box.move(550, 600)
    self.send_box.toggle()


    # Button for adding input boxes
    blade_button = QPushButton('Add', self)
    # THE PROBLEM IS THE NEXT LINE AS FAR AS I UNDERSTAND
    blade_button.clicked.connect(self.add_Bladebox)

   self.show()

# Method executes simulation:
def simulate(self):

    # TODO Read parameter values. Look explanations of parameters from 
simu_func.py



# 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())
    return box


# Method for label:
def label(self, left, top, text):
    lbl = QLabel(self)
    lbl.setText(text)
    lbl.resize(lbl.sizeHint())
    lbl.move(left,top)
    return lbl

# Method for adding blade boxes
def add_Bladebox(self):
    left=900
    top=500
    maxvalue=3
    step=1
    default=0
    decimals=1
    blade_box = self.inputBox(left, top, maxvalue, step, default, decimals)

0 个答案:

没有答案