Proper syntax of user input

Hi everyone! I have been trying to set a variable x to equal to the input of the user (x = input(“Please enter your name”)), but when I run the code, the instructions I have written within the input call doesn’t show up, all that shows up is a textbox (with no title) to type in. Not exactly sure what the syntax should be here, and would appreciate any help!
My code:

 def button_1_click(self, **event_args):
      x= input("Please enter your name!")
      if x!= "Michael":

Welcome to the forum!

Instead of the input statement, you can try adding a Textbox and setting the placeholder property of it to the prompt.

Here’s more information about Textbox
Anvil Docs | Textbox l

You can use an input_box to do that.

But before using it you should get familiar with how the alert with embedded components works.

And before you do that, you should get familiar with how forms in general work. Any tutorial will help with that.

Welcome to the Forum!

makes sense in a terminal or command-line program. But remember, you’re building a web page, instead. There is no text-based terminal window for input to use.

Instead, there is a web page, with whatever widgets you put there. Those widgets are the on-screen objects that can display your prompts, and receive your user’s keystrokes.

This can be a big conceptual leap, if you haven’t built any graphical programs before. If so, give it time. There are lots of new ideas, and it can take awhile to make them all connect together, well, in your head.

The biggest leap, for me, was sometimes called The Hollywood principle: “don’t call us, we’ll call you.” This turns conventional programming on its head.

  1. In a conventional (imperative) program, the program dictates what happens, in what order, from start to finish. The program calls upon the computer (and other things in its environment) to make that happen. input assumes that this is the case.
  2. But in a graphical program, the user is in control. They decide what to click on, where to type, and so on; and it’s the program’s job to respond to such calls-to-action. Suddenly, it’s not the program calling on its environment; the environment calls the program! This is the world that GUI programs work in, including what you write in Anvil.

This is greatly put. Thank you, helped shift my paradigm a little.

1 Like

I will try that out, thank you!

I’ll try to get familiar with what you suggested, I appreciate it!

That’s very true, I’m not exactly accustomed to building web pages, but your advice really does help and I appreciate it! It really changed the way I was viewing things.