-1

In Python, is it possible to have multiple input() fields that all can be edited before submitting to define variables, like a form?

For example:

var1 = input('num1: ')
var2 = input('num2: ')
var3 = input('num3: ')

When I run this code I have to fill in one after another. And once you filled in, you can't change your previous input. How can I make it that all 3 inputs are shown and I can still edit previous inputs like filling in a form?

robopyot
  • 21
  • 2
  • Submitting to what? Please give more detail about what are you trying to do. – khelwood Dec 26 '21 at 18:09
  • To define variables – robopyot Dec 26 '21 at 18:17
  • Can you try to elaborate with pseudo-code or by sketching what you want or anything else that leads in the direction of what you are trying to do? – eandklahn Dec 26 '21 at 18:35
  • Welcome to [Stack Overflow.](https://stackoverflow.com/ "Stack Overflow") Please be aware this is not a code-writing or tutoring service. We can help solve specific, technical problems, not open-ended requests for code or advice. Please edit your question to show what you have tried so far, and what specific problem you need help with. See the [How To Ask a Good Question](https://stackoverflow.com/help/how-to-ask "How To Ask a Good Question") page for details on how to best help us help you. – itprorh66 Dec 26 '21 at 18:41
  • You may define a function doing that with temporary variables. Still, you need some sort of information holder like a variable – AXOME Dec 26 '21 at 18:44
  • it is not clear what you want to do. Do you means some GUI with Text/Entry/Input fields? Python has standard module `tkinter` for GUI but you can use other frameworks like `PyQt`, `wxPython`. In text mode as standard you have only `input()` which you can't edit. You could try to use external module like `curses`, [rich](https://github.com/willmcgugan/rich), [textual](https://github.com/willmcgugan/textual) – furas Dec 26 '21 at 19:41
  • I added more explanation – robopyot Dec 26 '21 at 20:09

1 Answers1

1

not sure about your question try this code:

var1 = input('num1: ')
var2 = input('num2: ')
var3 = input('num3: ')


print('num1: ',var1,'num2: ', var2,'num3: ', var3)

var1 , var2, var3 = (input('num1 num2 num3 :').split())


print('num1: ',var1,'num2: ', var2,'num3: ', var3)

   

or:

import tkinter as tk



def printz():
    print('\n\nnum1: ',var1.get(),'num2: ', var2.get(),'num3: ', var3.get())

master = tk.Tk()

var1 = tk.StringVar()
var2 = tk.StringVar()
var3 = tk.StringVar()



tk.Label(master, text="num1").grid(row=0)
tk.Label(master, text="num2").grid(row=1)
tk.Label(master, text="num3").grid(row=2)
tk.Button(master,text ="Enter", command = printz,activebackground='green',
          justify='center').grid(row=3, column=1)

e1 = tk.Entry(master, textvariable=var1).grid(row=0, column=1)
e2 = tk.Entry(master, textvariable=var2).grid(row=1, column=1)
e3 = tk.Entry(master, textvariable=var3).grid(row=2, column=1)



master.mainloop()

that produces:

enter image description here

and var1, var2, var 3 as var1 = tk.StringVar()

pippo1980
  • 2,181
  • 3
  • 14
  • 30