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 6251575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:38:21+00:00 2026-05-24T13:38:21+00:00

I have a main PyQt window, from which I need to get a string

  • 0

I have a main PyQt window, from which I need to get a string of User Input when they hit a certain button.

Here is my code for the User Input window:

 class InputDialog(QtGui.QDialog):
   '''
   this is for when you need to get some user input text
   '''
   def __init__(self, parent=None, title='user input', label='comment', text=''):

       QtGui.QWidget.__init__(self, parent)

       #--Layout Stuff---------------------------#
       mainLayout = QtGui.QVBoxLayout()

       layout = QtGui.QHBoxLayout()
       self.label = QtGui.QLabel()
       self.label.setText(label)
       layout.addWidget(self.label)

       self.text = QtGui.QLineEdit(text)
       layout.addWidget(self.text)

       mainLayout.addLayout(layout)

       #--The Button------------------------------#
       layout = QtGui.QHBoxLayout()
       button = QtGui.QPushButton("okay") #string or icon
       self.connect(button, QtCore.SIGNAL("clicked()"), self.close)
       layout.addWidget(button)

       mainLayout.addLayout(layout)
       self.setLayout(mainLayout)

       self.resize(400, 60)
       self.setWindowTitle(title)

From the main window, I am saying:

inputter = InputDialog(mainWindowUI, title="comments", label="comments", text="")
inputter.show()
comment = inputter.text.text()
print comment

This prints an empty string, even if the user types a comment and hits “OK”. Obviously because the main window script does not wait on the InputDialog to close. So, how do I get it to wait, so that I may retrieve the user input?

  • 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-05-24T13:38:22+00:00Added an answer on May 24, 2026 at 1:38 pm

    Use

    inputter.exec_()
    

    instead of

    inputter.show()
    

    From: http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qdialog.html#exec

    This method is also a Qt slot with the C++ signature int exec().

    Shows the dialog as a modal dialog, blocking until the user closes it.
    The function returns a DialogCode result.

    If the dialog is application modal, users cannot interact with any
    other window in the same application until they close the dialog. If
    the dialog is window modal, only interaction with the parent window is
    blocked while the dialog is open. By default, the dialog is
    application modal.

    See also open(), show(), result(), and setWindowModality().

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a main window (#1) on my webpage from which I open a
I have a main table that I must get data from. I have a
i have a input tag which is non editable, but some times i need
i have a table called category in which i have main category ids and
I have a main asp.net app, which is written in asp.net 1.1. Runnning underneath
I have a main form and as sub form. I need the main Form
I have main thread which calls another thread. timeout period of second one is
I have a main JPanel which implements Scrollable and uses a BorderLayout. It contains
I have a main window: public class MainPanel extends JFrame implements MouseListener { public
I have a main canvas 'blackboard' in a panel, this canvas has itself several

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.