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

  • Home
  • SEARCH
  • 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 7842457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T16:19:36+00:00 2026-06-02T16:19:36+00:00

I am just trying to make a non-graphic game in Tkinter but am having

  • 0

I am just trying to make a non-graphic game in Tkinter but am having trouble with the entry widget. How can I wait for "<Return>" to be pressed before printing something?

    from Tkinter import *

    class App:
        def __init__(self, master):

            frame = Frame(master)
            frame.pack()
            f = Frame(master, width=500, height=300)
            f.pack(fill=X, expand=True)

            mt = StringVar()


            menubar = Menu(master)
            menubar.add_command(label="New Game", command=self.new_game)
            menubar.add_command(label="Continue Game", command=self.continue_game)
            master.config(menu=menubar)

            maintext = Label(master, fg="blue", textvariable=mt)
            maintext.pack(side=BOTTOM)
            mt.set("")

            self.e1 = Entry(master)
            self.e1.pack()
            self.e1.bind("<Return>")
            self.e1.lower()


            global mt


        def new_game(self):
            mt.set("What do you want your username to be?")
            self.e1.lift()
            #wait for <Return> to be pressed
                mt.set("Welcome " + self.e1.get())
        def continue_game(self):
            mt.set("Type your username in.")



    root = Tk()

    app = App(root)

    root.mainloop()

I want it to be when I click “New Game” on the top menubar, it shows the entry box and waits for me to type something in, and then click enter. THEN it prints out “Welcome”+(what the person types in). What actually happens is when I click New game, it immediately just prints “Welcome”.

By print, I mean aet the Label at the bottom to something else, which is reffered to by “mt.set”.

  • 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-02T16:19:37+00:00Added an answer on June 2, 2026 at 4:19 pm

    In GUI programs you don’t wait* for something to happen, you respond to events. So, to call a function when the user presses return you would do something like:

        self.e1.bind("<Return>", self._on_return)
    

    The above will call the function _on_return when the user presses the return key.

    In your specific code you don’t really need a StringVar. For example, you could do this:

    def __init__(self, master):
        ...
        self.maintext = Label(master, fg="blue")
        ...
    
    def _on_return(self, event):
        self.maintext.configure(text="Welcome, %s" % self.e1.get())
    

    * strictly speaking, you can wait for things, but that’s not the right way to write GUI programs except under specific circumstances, such as waiting for a dialog to be dismissed.

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

Sidebar

Related Questions

I am just messing around trying to make a game right now, but I
I'm trying to make it working for quite some time,but just can't seem to
I am just trying to make a vector, but it gives me a huge
How can I disable tinyMCE? I'm not trying to make tinyMCE not exist, just
I'm having trouble with suds . I'm trying to make a generic system to
i've been trying to enable Xdebug for Mac OS X Lion, but can't make
I'm still picking up ObjC and I'm just trying to make sure I understand
I just went through trying to make an alarm clock app with local notifications
I'm trying to make a RLE (Run-Length Encoder) Programme just for characters. I read
i'm trying to make a very simple YACC parser on Pascal language which just

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.