How do i make a username input interface (python)?

So i’m making a game in python processing and i need to have people input their names so it get’s attached to player 1 or player 2 etc…

def setup():
    name = input('enter your name')
    println('hi ' + str(name))
 
def input(name=''):
    from javax.swing import JOptionPane
    return JOptionPane.showInputDialog(frame, name)
1 Like

Hey, i mean like it as shown in the image.

You can take a look at this, if you want the Textfield to be part of the sketch :

Or you can use JTextField, which is a lot simpler, but will open an external JFrame window to set your Input.

Something like this :

void setup() {

}

void draw() {

}

void askNames() {
   JFrame nameFrame = new JFrame();
   nameFrame.setTitle(„Input Names“);

   JPanel name1Panel = new JPanel();
   JPanel name2Panel = new JPanel();
   
   JLabel name1Label = new JLabel(„Name1“);

   JLabel name2Label = new JLabel(„Name2“);

   JTextField name1TextField = new JTextField(„Name 1“, 15);
   JTextField name2TextField = new JTextField(„Name 2“, 15);

   name1Panel.add(name1Label);
   name2Panel.add(name2Label);

   name1Panel.add(name1TextField);
   name2Panel.add(name2TextField);

   nameFrame.add(name1Panel);
   nameFrame.add(name2Panel);

   nameFrame.setVisible();
}

ControlP5 is one option. Guido might be another.

1 Like