[PyQt] Problem how to click a button inside a group box? - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PyQt] Problem how to click a button inside a group box? (/thread-20325.html) |
Problem how to click a button inside a group box? - mart79 - Aug-05-2019 I have a button inside a groupbox which in turn is inside a larger group box. How do I run a function by clicking the button inside the groupbox? I have the following code: from PyQt5 import QtCore, QtGui, QtWidgets from propertyDialog import Ui_Dialog import sys class mainProgram(QtWidgets.QMainWindow, Ui_Dialog): def __init__(self, parent=None): super(mainProgram, self).__init__(parent) self.setupUi(self) self.cntPipe = 0 self.cntLiner = 0 self.cntCoating = 0 self.pipeproperty = {} self.liner = {} self.coating = {} self.response_AddPipe.clicked.connect(self.add_pipe) def add_pipe(self): self.cntPipe += 1 self.cntLiner = 0 self.cntCoating = 0 self.pipeproperty[self.cntPipe] = {} pipe_name = self.input_PipeName.text() self.pipeproperty[self.cntPipe]["Name"] = pipe_name pipe_OD = self.input_PipeOuterDiameter.text() self.pipeproperty[self.cntPipe]["Outside diameter"] = pipe_OD pipe_WT = self.input_PipeWallThickness.text() self.pipeproperty[self.cntPipe]["Wall thickness"] = pipe_WT pipe_density = self.input_PipeDensity.text() self.pipeproperty[self.cntPipe]["Density"] = pipe_density print(self.pipeproperty) I have no clue what to address such that it can find the push button "response_AddPipe".
RE: Problem how to click a button inside a group box? - Denni - Aug-05-2019 As stated on many forums when asking for help it behooves you greatly to give a MRE (Minimal Reproducible Example) of your issue - the key being Reproducible as in if I copy/paste what you have posted I can run it to see what you are seeing so that I can more easily help you with YOUR issue. So this would be a win-win for you in that your question will get answered faster. Giving code snippets that do not allow just copy/paste run means whomever might help you will either not help you or will be delayed in helping you. Now since you have not included an MRE I will have to guess the issue you are actually having appears somewhere else within your code because other than this code looking more complex than it needs to -- it appears (without being able to actually test it) that it would work just fine assuming everything else (that I cannot see) was coded correctly. This line calls the (I assume button) clicked event and if the rest is coded correctly should work just fine and call the "self.add_pipe" function without incident. self.response_AddPipe.clicked.connect(self.add_pipe) Note personally I would have used a semi-standard prefix of btnAddPipe to indicate this was a button rather than response_ because at a glance yours does not indicate at all that its a normal object like a button and as such could just as well as be anything else. RE: Problem how to click a button inside a group box? - mart79 - Aug-05-2019 (Aug-05-2019, 01:16 PM)Denni Wrote: As stated on many forums when asking for help it behooves you greatly to give a MRE (Minimal Reproducible Example) of your issue - the key being Reproducible as in if I copy/paste what you have posted I can run it to see what you are seeing so that I can more easily help you with YOUR issue. So this would be a win-win for you in that your question will get answered faster. Giving code snippets that do not allow just copy/paste run means whomever might help you will either not help you or will be delayed in helping you. Thanks for the advice and noted. I will keep it in mind for future questions. The problem has indeed been solved. |