Python Forum
PyQt5 - Get a parameter from a modal window
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PyQt5 - Get a parameter from a modal window
#1
Hello...I'd like some help.
I've created a main window in PyQt5 and another modal window which I need to catch a parameter from a radiobutton.
Here's the code(in the main window):
class JanelaModPag(QMainWindow):
   def __init__(self,m,items): 
     super().__init__()
     self.ui = Ui_ModPagam()
     self.ui.show()
How can I return to this with the parameter ?
Reply
#2
You'd better post a reproducible example. Nobody knows what Ui_ModPagam contains.
Reply
#3
(Nov-24-2025, 12:20 PM)Axel_Erfurt Wrote: You'd better post a reproducible example. Nobody knows what Ui_ModPagam contains.
class Ui_ModPagam(object):
    def setupUi(self, ModPagam,m,items):
        ModPagam.setObjectName("ModPagam")
        ModPagam.setWindowModality(QtCore.Qt.ApplicationModal)
        ModPagam.resize(408, 241)
        ModPagam.setMinimumSize(QtCore.QSize(408, 241))
        ModPagam.setMaximumSize(QtCore.QSize(408, 241))
        self.label = QtWidgets.QLabel(ModPagam)
        self.label.setGeometry(QtCore.QRect(130, 20, 151, 31))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(16)
        font.setBold(True)
        font.setWeight(75)
        self.label.setFont(font)
        self.label.setObjectName("label")
        self.label_2 = QtWidgets.QLabel(ModPagam)
        self.label_2.setGeometry(QtCore.QRect(30, 70, 331, 31))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(14)
        self.label_2.setFont(font)
        self.label_2.setObjectName("label_2")
        self.btnenviar = QtWidgets.QPushButton(ModPagam)
        self.btnenviar.setGeometry(QtCore.QRect(60, 180, 121, 31))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.btnenviar.setFont(font)
        self.btnenviar.setStyleSheet("background-color: rgb(170, 170, 255);")
        self.btnenviar.setObjectName("btnenviar")
        self.btnsair = QtWidgets.QPushButton(ModPagam)
        self.btnsair.setGeometry(QtCore.QRect(220, 180, 121, 31))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(14)
        font.setBold(True)
        font.setWeight(75)
        self.btnsair.setFont(font)
        self.btnsair.setStyleSheet("background-color: rgb(170, 170, 255);")
        self.btnsair.setObjectName("btnsair")
        self.rddin = QtWidgets.QRadioButton(ModPagam)
        self.rddin.setGeometry(QtCore.QRect(20, 120, 101, 17))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(14)
        self.rddin.setFont(font)
        self.rddin.setObjectName("rddin")
        self.rdpix = QtWidgets.QRadioButton(ModPagam)
        self.rdpix.setGeometry(QtCore.QRect(140, 120, 61, 17))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(14)
        self.rdpix.setFont(font)
        self.rdpix.setObjectName("rdpix")
        self.rdtransf = QtWidgets.QRadioButton(ModPagam)
        self.rdtransf.setGeometry(QtCore.QRect(220, 120, 161, 17))
        font = QtGui.QFont()
        font.setFamily("Arial")
        font.setPointSize(14)
        self.rdtransf.setFont(font)
        self.rdtransf.setObjectName("rdtransf")

        # Acrescentado
        
        self.btnenviar.setEnabled(False)
        self.grupo = QButtonGroup()
        self.grupo.addButton(self.rddin,1)
        self.grupo.addButton(self.rdpix,2)
        self.grupo.addButton(self.rdtransf,3)
        
        self.grupo.buttonToggled.connect(self.setarmodalidade)
        self.btnsair.clicked.connect(ModPagam.close)

        self.retranslateUi(ModPagam)
        QtCore.QMetaObject.connectSlotsByName(ModPagam)

    def retranslateUi(self, ModPagam):
        _translate = QtCore.QCoreApplication.translate
        ModPagam.setWindowTitle(_translate("ModPagam", "SISADM - Sistema de Administração"))
        self.label.setText(_translate("ModPagam", "MODALIDADE"))
        self.label_2.setText(_translate("ModPagam", "Selecione a modalidade de pagamento"))
        self.btnenviar.setText(_translate("ModPagam", "ENVIAR"))
        self.btnsair.setText(_translate("ModPagam", "SAIR"))
        self.rddin.setText(_translate("ModPagam", "Dinheiro"))
        self.rdpix.setText(_translate("ModPagam", "Pix"))
        self.rdtransf.setText(_translate("ModPagam", "Transf. Bancária"))

    def converteritens(self,items):
      itemconvert = ""
      div = ","
      if len(items) == 1:
        itemconvert = items[0]
      else:
        for i in range(len(items)):
          if i == len(items):
            itemconvert = itemconvert+items[i]
          else:
            itemconvert = itemconvert+items[i]+div
      return itemconvert
    
    def setarmodalidade(self,button,checked):
      global mod
      if checked:
        mod = button.property("text") # Obtém o valor associado
        self.btnenviar.setEnabled(True)
    
Reply
#4
This is all not reproducible.

     self.ui = Ui_ModPagam()
     self.ui.show()
Ui_ModPagam has nothing to show, there is no window.

def __init__(self,m,items): 
What is m,items?
Reply
#5
(Nov-24-2025, 01:19 PM)Axel_Erfurt Wrote: This is all not reproducible.

     self.ui = Ui_ModPagam()
     self.ui.show()
Ui_ModPagam has nothing to show, there is no window.

def __init__(self,m,items): 
What is m,items?
These are the parameters that I'd like to pass to the modal...but changed my mind and forgot to delete. Decided to capture value from radio in modal and return execution to the window that calls it.
Reply
#6
Is ModPagam supposed to act like a dialog? Making a window modal keeps it on top and keep focus, it does not make it a dialog. A dialog blocks the main window code from running until the dialog is closed. Closing the dialog is how the user tells the program that all input is entered in the dialog. To act this way, a dialog has its own exec() loop.

The best way to make a dialog is subclass the QDialog class. I don't use QtDesigner, but I found a tutorial about using designer to create dialogs.

https://www.pythonguis.com/tutorials/cre...-designer/
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Pyqt5 - Close a modal window Ninja2112 9 2,843 Apr-23-2025, 02:56 PM
Last Post: deanhystad
  [Tkinter] Modal window DPaul 16 14,371 Nov-05-2024, 04:18 PM
Last Post: kaliumster
  Interaction between Matplotlib window, Python prompt and TKinter window NorbertMoussy 3 4,032 Mar-17-2024, 09:37 AM
Last Post: deanhystad
  [PyQt] PyQt5 window closing when trying to display a graph bianca 4 5,735 Aug-12-2023, 03:25 PM
Last Post: bianca
  tkinter window and turtle window error 1885 3 9,519 Nov-02-2019, 12:18 PM
Last Post: 1885
  Huge code problems (buttons(PyQt5),PyQt5 Threads, Windows etc) ZenWoR 0 4,034 Apr-06-2019, 11:15 PM
Last Post: ZenWoR
  [PyQt] Can't show PyQt5 mediaPlayer in window DecaK 1 6,970 Sep-15-2018, 09:54 AM
Last Post: Axel_Erfurt
  Closing Modal Window in QT nieselfriem 0 5,978 Apr-19-2017, 03:32 PM
Last Post: nieselfriem
  update a variable in parent window after closing its toplevel window gray 5 12,692 Mar-20-2017, 10:35 PM
Last Post: Larz60+
  Show GPG keys in pyqt5 window Fred Barclay 1 5,852 Oct-24-2016, 07:09 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

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