- #1
Mckamar
- 1
- 0
I'm new to this forum, as well as Python, so bare with me, won't you:)
Ok, so I have this GUI written in python and utilizing PYQT5. I have a functioning version, but I now want to add a QpushButton that executes a method called add_Bladebox. This method adds a doublespinbox to the gui. The method works fine when I call it as part of the code, but when I try to execute it via the QpushButton, nothing happens. I know that without a loop, I could only ever do it once anyway(no position change implemented), but I can add that feature later. So any suggestion as to why it's not working is well appreciated. Thanks in advance!
[/code]
Ok, so I have this GUI written in python and utilizing PYQT5. I have a functioning version, but I now want to add a QpushButton that executes a method called add_Bladebox. This method adds a doublespinbox to the gui. The method works fine when I call it as part of the code, but when I try to execute it via the QpushButton, nothing happens. I know that without a loop, I could only ever do it once anyway(no position change implemented), but I can add that feature later. So any suggestion as to why it's not working is well appreciated. Thanks in advance!
Python:
[code=Python]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
NavigationToolbarclass 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)