Bottom Page

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".
Quote
#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.
Quote
#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.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Problem with Submit button Tkinter Reldaing 2 206 Jan-05-2020, 01:58 AM
Last Post: balenaucigasa
  [Tkinter] Checking button click in Tkinter GalaxyCoyote 3 506 Oct-20-2019, 03:28 AM
Last Post: GalaxyCoyote
  [PySimpleGui] How to alter mouse click button of a standard submit button? skyerosebud 3 680 Jul-21-2019, 06:02 PM
Last Post: FullOfHelp
  [Tkinter] Tkinter window pop up again when i click button Orimura_Sandy 1 905 May-12-2019, 08:17 PM
Last Post: joe_momma
  [Tkinter] Not getting entry values on button click & treeview not updating ? swanysto 4 1,920 May-10-2019, 04:16 PM
Last Post: swanysto
  Simple Button click on image file to create action? jpezz 4 753 Mar-27-2019, 10:08 PM
Last Post: jpezz
  right mouse button click with PyQt5 brecht83 4 6,193 Nov-09-2018, 02:55 PM
Last Post: brecht83
  [Tkinter] loop function when called from tkinter button click WantedStarling 5 3,082 Jul-13-2018, 06:12 PM
Last Post: nilamo
  Tkinter touch screen button click ashtona 2 3,499 Apr-13-2018, 11:46 AM
Last Post: buran
  Button click doesnt work from my second class/layout in Python imamideb 0 940 Feb-13-2018, 12:09 PM
Last Post: imamideb

Forum Jump:


Users browsing this thread: 1 Guest(s)