Python Forum
[PyQt] Problem how to click a button inside a group box?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] Problem how to click a button inside a group box?
#1
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)
Error:
"C:\Users\USr\Desktop\Work Folder PPM\VirtualEnvironment\Scripts\python.exe" "C:/Users/USr/Desktop/Work Folder PPM/VirtualEnvironment/Scripts/Complete Program.py" Traceback (most recent call last): File "C:/Users/USr/Desktop/Work Folder PPM/VirtualEnvironment/Scripts/Complete Program.py", line 74, in <module> main() File "C:/Users/USr/Desktop/Work Folder PPM/VirtualEnvironment/Scripts/Complete Program.py", line 67, in main nextGui = mainProgram() File "C:/Users/USr/Desktop/Work Folder PPM/VirtualEnvironment/Scripts/Complete Program.py", line 17, in __init__ self.response_AddPipe.clicked.connect(self.add_pipe) AttributeError: 'mainProgram' object has no attribute 'response_AddPipe' Process finished with exit code 1
I have no clue what to address such that it can find the push button "response_AddPipe".
Reply
#2
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.
Reply
#3
(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.

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.

Thanks for the advice and noted. I will keep it in mind for future questions.
The problem has indeed been solved.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  problem with radio button crook79 3 535 Aug-12-2021, 02:30 PM
Last Post: deanhystad
  [Tkinter] image inside button rwahdan 4 640 Jul-12-2021, 08:49 PM
Last Post: deanhystad
  [Kivy] Acces atributes from a button defined in a class inside the .kv Tomli 2 560 Jun-10-2021, 01:05 AM
Last Post: Tomli
  [Tkinter] Modify Class on Button Click KDog 4 1,762 May-11-2021, 08:43 PM
Last Post: KDog
  tkinter python button position problem Nick_tkinter 3 1,117 Jan-31-2021, 05:15 AM
Last Post: deanhystad
  [Tkinter] Button click problem using OOP JohnB 5 1,031 Oct-21-2020, 12:43 PM
Last Post: JohnB
  tkinter | Button color text on Click Maryan 2 1,223 Oct-09-2020, 08:56 PM
Last Post: Maryan
  Closing window on button click not working kenwatts275 4 1,104 May-03-2020, 01:59 PM
Last Post: deanhystad
  Problem about image and button scotesse 5 1,184 Apr-27-2020, 10:09 AM
Last Post: scotesse
  Problem with Submit button Tkinter Reldaing 2 1,593 Jan-05-2020, 01:58 AM
Last Post: balenaucigasa

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020