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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T16:40:56+00:00 2026-06-17T16:40:56+00:00

I am working on a text based game in PyQt. I have a QTextDisplay

  • 0

I am working on a text based game in PyQt. I have a QTextDisplay for the “window” and a QLineEdit for the actual prompt. They are hooked up so that when the user hits the return key in the line edit, it appears in the text display. Unfortunately, this needs to be a GUI application and not a simple command program because there needs to be pictures (not my decision).

I would like the execution to pause and wait for user input into the line edit (much like input() works in a command application). QInputDialog behaves in this way, except launches a dialog box. This is pretty cumbersome. I have tried while loops, but it doesn’t look like PyQt likes them (it hangs and doesn’t actually hit the app.exec_()).

On a side note, because of the dislike of the while loop, how would I go about writing a game loop in Qt? Should I use a QThread?

  • 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-17T16:40:57+00:00Added an answer on June 17, 2026 at 4:40 pm

    I think you can do what you want with just signal and slots. Qt runs it’s own event loop, you should not try to write a second one on top of it.

    In the class that handles interpreating the input add a slot deal_with_input and then connect the signal editingFinished to it.

    ex:

    class main_window(QTextDisplay):
        def __init__(self,input_widget,parent=self,*arg,**kwargs):
            QTextDisplay.__init__(self,parent=parent) # and what ever other args you use
            self.input_widget = input_widget
    
            self.input_widget.editingFinished.connect(self.proc_input)
    
            ## what ever other set up you do
    
        @QtCore.Slot()
        def proc_input(self):
            input_str = self.input_widget.text()
            if input_str = '':
                return
            self.input_widget.clear()
    
            # do what ever it is you do with the input text, update the display
    

    You can quible over the exact class design (maybe you don’t want this logic embeded in you text display widget), but the logic will hold.

    Basically, Qt will sit there, doing nothing, until the user pokes it, and then it will process the keyboard/mouse events resize, whatever. When the user hits return in the QLineEdit widget, the widget emits the signal editingFinished (doc). We connect that to a Slot which we created, which basically just waits for a signal to trigger it (signal and slots are just a well thought out type-safe callback scheme). Once the slot recives the signal, it executes it’s function and then goes back to waiting. (In this case, the function grabs the text from the line edit box, clears the box, and then does what ever your game code needs to do).

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

Sidebar

Related Questions

I have a little text based game i am working on. The user has
I am working on a text-based game in Python 3.1 that would use timing
I'm working on a text-based adventure game project. It involves rooms with items in
I'm working on a text-based adventure game project. It involves rooms with items in
This is driving me nuts. I have a working text based application. It has
I'm working on a text based game for fun and I'm struggling with inheritance
I have a python web server, with a custom text based game and blog.
I am working on a little text based console game using Python. Because I
All, Working on a custom TCP/IP server for a text-based multiplayer game, using Ruby.
I am currently working on a text based game in C and I'm having

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.