Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8240145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T20:23:16+00:00 2026-06-07T20:23:16+00:00

Trying to build a user interface using PyQt4. Got a dialog window that pops

  • 0

Trying to build a user interface using PyQt4. Got a dialog window that pops up, and I want it to do something then close, when ‘Ok’ is pressed. Unfortunately, I can’t seem to get it working – tried all sorts of combinations of Dialog.exec_(), Dialog.close(), self.exec_(), self.close(), emitting an ‘accepted’ signal to Dialog.accept, etc. So far, nothing has worked, and I’m not quite sure why. Here’s the code for it:

Dialog window initialised as such;

def begin_grab(self):
    self.GrabIm=qtg.QDialog(self)
    self.GrabIm.ui=Ui_Dialog()
    self.GrabIm.ui.setupUi(self.GrabIm)
    self.GrabIm.show()

Dialog window;

class Ui_Dialog(object):

    def setupUi(self, Dialog):
        Dialog.setObjectName(_fromUtf8("Dialog"))
        ...
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("accepted()")), self.accept)
        QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL(_fromUtf8("rejected()")), Dialog.reject)
        QtCore.QMetaObject.connectSlotsByName(Dialog)

    def accept(self):
        if self.radioButton.isChecked()==True: #assume it is true
            #Call continuous grabber
            print "Grabbing continuously"
            Dialog.exec_() #Close it here
        else:
            #Call trigger server
            print "Grabbing triggered"
            self.exec_()

The main thing that keeps happening is either a message saying ‘Dialog’ is an unknown variable, in the accept() function, or if I use self.exec_() or similar it says exec_() is not a known attribute. If I try doing accept(self, Dialog), and put self.accept(Dialog) in the connect statement, it also crashes.

Any and all help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T20:23:18+00:00Added an answer on June 7, 2026 at 8:23 pm

    You are doing it pretty wrong. You shouldn’t modify the Qt Designer generated code (Ui_Dialog). You should subclass QDialog and define the accept there:

    class MyDialog(QtGui.QDialog):
        def __init__(self, parent=None):
            super(MyDialog, self).__init__(parent)
            self.ui = Ui_Dialog()
            self.ui.setupUi(self)
            # use new style signals
            self.ui.buttonBox.accepted.connect(self.accept)
            self.ui.buttonBox.rejected.connect(self.reject)
    
        def accept(self):
            if self.ui.radioButton.isChecked(): # no need to do ==True
                #Call continuous grabber
                print "Grabbing continuously"
            else:
                #Call trigger server
                print "Grabbing triggered"
            super(MyDialog, self).accept()  # call the accept method of QDialog. 
                                               # super is needed 
                                               # since we just override the accept method
    

    Then you initialize it as:

    def begin_grab(self):
        self.GrabIm=MyDialog(self)
        self.GrabIm.exec_()  # exec_() for modal dialog
                               # show() for non-modal dialog
    

    But looking at your code, I wouldn’t do it that way. Let the dialog return with accept/reject and then do your conditional stuff in the caller (i.e. Main window):

    class MyDialog(QtGui.QDialog):
        def __init__(self, parent=None):
            super(MyDialog, self).__init__(parent)
            self.ui = Ui_Dialog()
            self.ui.setupUi(self)
            # use new style signals
            self.ui.buttonBox.accepted.connect(self.accept)
            self.ui.buttonBox.rejected.connect(self.reject)
    

    and the caller code:

    def begin_grab(self):
        self.GrabIm=MyDialog(self)
        if self.GrabIm.exec_():  # this will be True if dialog is 'accept'ed, False otherwise
            if self.GrabIm.ui.radioButton.isChecked():
                #Call continuous grabber
                print "Grabbing continuously"
            else:
                #Call trigger server
                print "Grabbing triggered"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a user management interface for an app that is
I'm trying to build a quick administrative interface using the built in Windows.Forms PropertyGrid
What I am exactly trying to build is, an INTERFACE through which a user
I'm trying to build a WPF user interface containing a TabControl, and a TextBlock.
am trying here to build rss reader , the problem that when user finish
Im trying to build a page that will allow a user to select a
I am trying to build a generic interface that can accept a List of
I'm trying to build a small testing app with erlang+mnesia. I have a user
I am trying to build a shopping cart site. When a user click add
I am trying to build a shopping website with ajax. When a user clicks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.