Hello, I'm sure there is a simple solution to this but I cannot seem to find the information I need in my textbook or online.

I'm creating a GUI with an entry box for the user to input their name.
I then use getText() to retrieve the name they entered and call it "player".
PROBLEM: What I want to do is incorporate the variable name "player" into the string in the text object (line 2).
How do I mix both strings AND variables in this particular part of the code?

player = enterName.getText()
greeting = Text(Point(300, 250), "Hello," player, "and good night")
greeting.setFill("white")
greeting.draw(win)

Thanks in advance!

Recommended Answers

All 2 Replies

Try
greeting = Text(Point(300, 250), "Hello," + player + "and good night")
Otherwise:
print_str = "Hello," + player + "and good night"
greeting = Text(Point(300, 250), print_str)

@jenzilla:

I dont know how far will this help you , but there is a module called easygui which is really very very easy to use , your question can be done soo easily

from easygui import *
name =  enterbox (" Welcome user , please enter your name " , "My APP ")
msgbox("Hello" + str(name) + " \n Press ok to quit" )
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.