User input/Graphical: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
m (→‎{{header|Perl}}: XUL is no longer supported by Mozilla)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(37 intermediate revisions by 16 users not shown)
Line 1:
{{task|Text processing}}[[Category:GUI]][[Category:Basic language learning]]{{requires|Graphics}}
[[Category:GUI]]
[[Category:Basic language learning]]
{{requires|Graphics}}
 
In this task, the goal is to input a string and the integer 75000, from [[graphical user interface]].
 
 
See also: [[User input/Text]]
<br><br>
 
=={{header|AArch64 Assembly}}==
{{works with|as|Raspberry Pi 3B version Buster 64 bits}}
<syntaxhighlight lang="aarch64 assembly">
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program inputWin64.s */
 
/*******************************************/
/* Constantes file */
/*******************************************/
/* for this file see task include a file in language AArch64 assembly*/
.include "../includeConstantesARM64.inc"
 
.equ YPOSTEXTINPUT, 18
.equ LGBUFFER, 50
.equ FONTSIZE, 6
/* constantes X11 */
.equ KeyPressed, 2
.equ ButtonPress, 4
.equ ButtonPress, 4
.equ EnterNotify, 7
.equ LeaveNotify, 8
.equ ClientMessage, 33
.equ KeyPressMask, 1
.equ ButtonPressMask, 4
.equ ButtonReleaseMask, 8
.equ ExposureMask, 1<<15
.equ StructureNotifyMask, 1<<17
.equ EnterWindowMask, 1<<4
.equ LeaveWindowMask, 1<<5
 
.equ CWBorderWidth, 1<<4
 
 
/* structures descriptions are in end oh this program */
 
/*******************************************/
/* Initialized data */
/*******************************************/
.data
szRetourligne: .asciz "\n"
szMessErreur: .asciz "Server X11 not found.\n"
szMessErrfen: .asciz "Error create X11 window.\n"
szMessErrGC: .asciz "Error create Graphic Context.\n"
szMessErrButton: .asciz "Error create button.\n"
szMessErrButtonGC: .asciz "Error create button Graphic Context.\n"
szMessErrInput: .asciz "Error create input window.\n"
szMessErrInputGC: .asciz "Error create input Graphic Context.\n"
//szMessGoodBye: .asciz "There have been no clicks yet"
szCursor: .asciz "_"
szTextButton: .asciz "PUSH"
szMessResult: .asciz "Text : @ Value @ "
szLibText: .asciz "Text :"
szLibValue: .asciz "Value : "
 
szLibDW: .asciz "WM_DELETE_WINDOW" // message close window
 
/*******************************************/
/* UnInitialized data */
/*******************************************/
.bss
.align 4
qDisplay: .skip 8 // Display address
qDefScreen: .skip 8 // Default screen address
identWin: .skip 8 // window ident
qCounterClic: .skip 8 // counter clic button
//qLongTexte: .skip 8
//ptZoneS: .skip 8 // pointeur zone saisie
ptMessage: .skip 8 // final message pointer
sZoneConv: .skip 24
wmDeleteMessage: .skip 16 // ident close message
stEvent: .skip 400 // provisional size
 
stButton: .skip BT_fin
buffer: .skip 500
stInputText: .skip Input_fin
stInputValue: .skip Input_fin
stWindowChge: .skip XWCH_fin
sSaisieCar: .skip LGBUFFER
sTexteSaisi: .skip LGBUFFER
sValueSaisi: .skip LGBUFFER
key: .skip 4 // code touche
/**********************************************/
/* -- Code section */
/**********************************************/
.text
.global main // program entry
main: // INFO: main
mov x0,#0 // open server X
bl XOpenDisplay
cmp x0,#0
beq erreur
// Ok return Display address
ldr x1,qAdrqDisplay
str x0,[x1] // store Display address for future use
mov x28,x0 // and in register 28
ldr x2,[x28,Disp_default_screen] // load default screen
ldr x1,qAdrqDefScreen
str x2,[x1] //store default_screen
mov x2,x28
ldr x0,[x2,Disp_screens] // screen list
//screen areas
ldr x5,[x0,Screen_white_pixel] // white pixel
ldr x3,[x0,Screen_black_pixel] // black pixel
ldr x4,[x0,Screen_root_depth] // bits par pixel
ldr x1,[x0,Screen_root] // root windows
// create window x11
mov x0,x28 //display
mov x2,#0 // position X
mov x3,#0 // position Y
mov x4,600 // weight
mov x5,400 // height
mov x6,0 // bordure ???
ldr x7,0 // ?
ldr x8,qBlanc // background
str x8,[sp,-16]! // argument fot stack
bl XCreateSimpleWindow
add sp,sp,16 // for stack alignement
cmp x0,#0 // error ?
beq erreurF
ldr x1,qAdridentWin
str x0,[x1] // store window ident for future use
mov x27,x0 // and in register 27
 
// Correction of window closing error
mov x0,x28 // Display address
ldr x1,qAdrszLibDW // atom name address
mov x2,#1 // False create atom if not exist
bl XInternAtom
cmp x0,#0
ble erreurF
ldr x1,qAdrwmDeleteMessage // address message
str x0,[x1]
mov x2,x1 // address atom create
mov x0,x28 // display address
mov x1,x27 // window ident
mov x3,#1 // number of protocoles
bl XSetWMProtocols
cmp x0,#0
ble erreurF
// authorization of seizures
mov x0,x28 // display address
mov x1,x27 // window ident
ldr x2,qFenetreMask // mask
bl XSelectInput
cmp x0,#0
ble 99f
// create Graphic Context
mov x0,x28 // display address
mov x1,x27 // window ident
bl createGC // GC address -> x26
cbz x0,erreurF
// create Graphic Context 1
mov x0,x28 // display address
mov x1,x27 // window ident
bl createGC1 // GC address -> x25
cbz x0,erreurF
// Display window
mov x1,x27 // ident window
mov x0,x28 // Display address
bl XMapWindow
 
ldr x0,qAdrszLibText
mov x1,x27
mov x2,5
mov x3,70
bl displayText
ldr x0,qAdrszLibValue
mov x1,x27
mov x2,280
mov x3,70
bl displayText
bl createButton // create button on screen
 
bl createInputText // create input text window
 
bl createInputValue // create input value window
 
1: // events loop
bl traitEvents
// other events
cbz x0,1b // and loop
//TODO: close ??
mov x0,0 // end Ok
b 100f
//TODO: close ??
 
3:
ldr x0,qAdrstEvent // events structure address
bl evtButtonMouse
b 1b
 
erreurF: // error create window
ldr x0,qAdrszMessErrfen
bl affichageMess
mov x0,1
b 100f
erreur: // error no server x11 active
ldr x0,qAdrszMessErreur
bl affichageMess
mov x0,1
100: // program standard end
mov x8,EXIT
svc 0
qBlanc: .quad 0xF0F0F0F0
qAdrqDisplay: .quad qDisplay
qAdrqDefScreen: .quad qDefScreen
qAdridentWin: .quad identWin
qAdrstEvent: .quad stEvent
qAdrszMessErrfen: .quad szMessErrfen
qAdrszMessErreur: .quad szMessErreur
qAdrwmDeleteMessage: .quad wmDeleteMessage
qAdrszLibDW: .quad szLibDW
//qAdrszMessGoodBye: .quad szMessGoodBye
qAdrszLibText: .quad szLibText
qAdrszLibValue: .quad szLibValue
qFenetreMask: .quad KeyPressMask|ButtonPressMask|StructureNotifyMask|ExposureMask|EnterWindowMask
/********************************************************************/
/* Events ***/
/********************************************************************/
traitEvents: // INFO: traitEvents
stp x20,lr,[sp,-16]! // save registers
mov x0,x28 // Display address
ldr x1,qAdrstEvent // events structure address
bl XNextEvent
ldr x0,qAdrstEvent // events structure address
ldr x1,[x0,#XAny_window] // what window ?
cmp x1,x27 // main window ?
bne 1f
bl evtMainWindow // yes
b 100f
1:
ldr x10,qAdrstInputText // input text window ?
ldr x11,[x10,Input_adresse]
cmp x1,x11
bne 2f
bl evtInputWindowText
mov x0,0 // other events
b 100f
2:
ldr x10,qAdrstInputValue // input value window
ldr x11,[x10,Input_adresse]
cmp x1,x11
bne 3f
bl evtInputWindowValue
mov x0,0 // other events
b 100f
3:
ldr x10,[x0,XAny_window] // window of event
ldr x11,qAdrstButton // load button ident
ldr x12,[x11,BT_adresse]
cmp x10,x12 // equal ?
bne 4f // no
bl evtButton
mov x0,0 // other events
b 100f
4: // other windows
mov x0,0 // other events
100:
ldp x20,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
/******************************************************************/
/* main windows events */
/******************************************************************/
/* x0 contains the events */
/* x1 contains the ident Window */
/* x0 return 0 if continue , 1 if program end */
evtMainWindow: // INFO: evtMainWindow
stp x20,lr,[sp,-16]! // save registers
ldr w0,[x0] // type in 4 first bytes
cmp w0,#ClientMessage // message for close window
beq 2f // yes -> end
mov x0,0 // other events
b 100f // and loop
2:
ldr x0,qAdrstEvent // events structure address
ldr x1,[x0,56] // location message code
ldr x2,qAdrwmDeleteMessage // equal ?
ldr x2,[x2]
mov x0,0
cmp x1,x2
bne 100f // no loop
mov x0,1 // end program
100:
ldp x20,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
/******************************************************************/
/* input text windows events */
/******************************************************************/
/* x0 contains the events */
/* x1 contains the ident Window */
evtButton: // INFO: evtButton
stp x20,lr,[sp,-16]! // save registers
ldr x10,[x0,#XAny_type]
cmp x10,ButtonPress
bne 1f
bl evtButtonMouse
b 100f
1:
cmp x10,#EnterNotify // mouse is on the button
bne 2f
ldr x3,qAdrstWindowChge // and change window border
mov x2,3
str x2,[x3,#XWCH_border_width]
mov x0,x28 // display
ldr x2,qFenSMask
bl XConfigureWindow
b 100f
2:
cmp x10,#LeaveNotify // mouse is off the button
bne 3f
ldr x3,qAdrstWindowChge // and change window border
mov x2,1
str x2,[x3,#XWCH_border_width]
mov x0,x28 // display
ldr x2,qFenSMask
bl XConfigureWindow
b 100f
3: // other event
100:
ldp x20,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
/******************************************************************/
/* input text windows events */
/******************************************************************/
/* x0 contains the events */
/* x1 contains the ident Window */
evtInputWindowText: // INFO: evtInputWindowText
stp x20,lr,[sp,-16]! // save registers
ldr x10,[x0,#XAny_type]
mov x20,x1
cmp x10,#KeyPressed // key character ?
bne 2f
// x0 events x1 window ident
ldr x2,qAdrstInputText
bl traitImput
b 100f
2:
cmp x10,#EnterNotify // mouse is on the window
bne 3f
ldr x0,qAdrstInputText // display text and cursor
bl displayInput
mov x1,x20
ldr x3,qAdrstWindowChge // and change window border
mov x2,3
str x2,[x3,#XWCH_border_width]
mov x0,x28 // display
ldr x2,qFenSMask
bl XConfigureWindow
b 100f
3:
cmp x10,#LeaveNotify // the mouse is out the window
bne 4f
ldr x0,qAdrszCursor // erase the cursor
ldr x2,qAdrstInputText
ldr x2,[x2,Input_cursor]
mov x10,FONTSIZE
mul x2,x2,x10
mov x3,YPOSTEXTINPUT
bl eraseText1
mov x1,x20
ldr x3,qAdrstWindowChge // and chane window border
mov x2,1
str x2,[x3,#XWCH_border_width]
mov x0,x28 // display
ldr x2,qFenSMask
bl XConfigureWindow
b 100f
4: // other event
100:
ldp x20,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qFenSMask: .quad CWBorderWidth
qAdrstWindowChge: .quad stWindowChge
/******************************************************************/
/* input text windows events */
/******************************************************************/
/* x0 contains the events */
/* x1 contains the ident Window */
evtInputWindowValue: // INFO: evtInputWindowValue
stp x20,lr,[sp,-16]! // save registers
ldr x10,[x0,#XAny_type]
mov x20,x1
cmp x10,#KeyPressed // cas d'une touche
bne 2f
// x0 events x1 window ident
ldr x2,qAdrstInputValue
bl traitImput
b 100f
2:
cmp x10,#EnterNotify // mouse is on the window
bne 3f
ldr x0,qAdrstInputValue // display text and cursor
bl displayInput
mov x1,x20
ldr x3,qAdrstWindowChge // and change window border
mov x2,3
str x2,[x3,#XWCH_border_width]
mov x0,x28 // display
ldr x2,qFenSMask
bl XConfigureWindow
b 100f
3:
cmp x10,#LeaveNotify // the mouse is out the window
bne 4f
ldr x0,qAdrszCursor // erase the cursor
ldr x2,qAdrstInputValue
ldr x2,[x2,Input_cursor]
mov x10,FONTSIZE
mul x2,x2,x10
mov x3,YPOSTEXTINPUT
bl eraseText1
mov x1,x20
ldr x3,qAdrstWindowChge // and chane window border
mov x2,1
str x2,[x3,#XWCH_border_width]
mov x0,x28 // display
ldr x2,qFenSMask
bl XConfigureWindow
b 100f
4: // other event
100:
ldp x20,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
 
/******************************************************************/
/* traitement Key pressed */
/******************************************************************/
/* x0 contains the event */
/* x1 contains the ident Window */
/* x2 contains address structure window*/
traitImput: // INFO: traitImput
stp x20,lr,[sp,-16]! // save registers
mov x20,x2 // save structure address
mov x21,x1 // save ident window
ldr x1,qAdrsSaisieCar // character input buffer
mov x2,#4 // buffer lenght
ldr x3,qAdrkey // code character
mov x4,0 // Specifies or returns the XComposeStatus structure or NULL.
bl XLookupString
cmp x0,#1 // character key ?
bne 1f
ldr x0,qAdrsSaisieCar // input character area
ldrb w22,[x0] // load byte
cmp x22,#13 // enter ?
beq 1f
ldr x0,[x20,Input_text] // erase input area
mov x1,x21
mov x2,0
mov x3,YPOSTEXTINPUT
bl eraseText1
ldr x0,qAdrszCursor
ldr x2,[x20,Input_cursor] // erase cursor
mov x1,x21
mov x10,FONTSIZE // Font size
mul x2,x2,x10
mov x3,YPOSTEXTINPUT
bl eraseText1
ldr x13,[x20,Input_text]
cmp x22,#8 // back
beq back
// voir autre touche
ldr x4,[x20,Input_cursor] //
strb w22,[x13,x4] // store input character at text end
add x4,x4,1
str x4,[x20,Input_cursor] // maj cursor location
b suiteaff
back:
ldr x4,[x20,Input_cursor] // text size
sub x4,x4,#1
str x4,[x20,Input_cursor] // maj cursor location
suiteaff:
strb wzr,[x13,x4] // zero -> text end
mov x0,x20
bl displayInput
b 100f
1: // other key
mov x0,x28
mov x1,#50
bl XBell // sound on
 
100:
ldp x20,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrsSaisieCar: .quad sSaisieCar
qAdrkey: .quad key
qAdrsTexteSaisi: .quad sTexteSaisi
/******************************************************************/
/* create Graphic Context */
/******************************************************************/
/* x0 contains the Display address */
/* x1 contains the ident Window */
createGC: // INFO: createGC
stp x20,lr,[sp,-16]! // save registers
mov x20,x0 // save display address
mov x2,#0
mov x3,#0
bl XCreateGC
cbz x0,99f
mov x26,x0 // save GC
mov x0,x20 // display address
mov x1,x26
ldr x2,qRed // code RGB color
bl XSetForeground
cbz x0,99f
mov x0,x26 // return GC
b 100f
99:
ldr x0,qAdrszMessErrGC
bl affichageMess
mov x0,0
100:
ldp x20,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrszMessErrGC: .quad szMessErrGC
qRed: .quad 0xFF0000
qGreen: .quad 0xFF00
qBlue: .quad 0xFF
qBlack: .quad 0x0
/******************************************************************/
/* create Graphic Context 1 */
/******************************************************************/
/* x0 contains the Display address */
/* x1 contains the ident Window */
createGC1: // INFO: createGC1
stp x20,lr,[sp,-16]! // save registers
mov x20,x0 // save display address
mov x2,#0
mov x3,#0
bl XCreateGC
cbz x0,99f
mov x25,x0 // save GC
mov x0,x20 // display address
mov x1,x25
ldr x2,qBlanc // code RGB color
bl XSetForeground
cbz x0,99f
mov x0,x25 // return GC1
b 100f
99:
ldr x0,qAdrszMessErrGC
bl affichageMess
mov x0,0
100:
ldp x20,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
/******************************************************************/
/* create button on screen */
/******************************************************************/
createButton: // INFO: createButton
stp x21,lr,[sp,-16]! // save registers
// create button window
mov x0,x28 // display address
mov x1,x27 // ident window
mov x2,500 // X position
mov x3,50 // Y position
mov x4,60 // weight
mov x5,30 // height
mov x6,1 // border
ldr x7,qBlack
ldr x8,qBlanc // background
str x8,[sp,-16]! // argument fot stack
bl XCreateSimpleWindow
add sp,sp,16 // for stack alignement
cmp x0,#0 // error ?
beq 99f
ldr x21,qAdrstButton
str x0,[x21,BT_adresse] // save ident button
str xzr,[x21,BT_cbdata] // for next use
 
// autorisation des saisies
mov x0,x28 // display address
ldr x1,[x21,BT_adresse] // button address
ldr x2,qButtonMask // mask
bl XSelectInput
// create Graphic Contexte of button
mov x0,x28 // display address
ldr x1,[x21,BT_adresse] // button ident
mov x2,#0
mov x3,#0
bl XCreateGC
cmp x0,#0
beq 98f
str x0,[x21,BT_GC] // store GC
// display button
mov x0,x28 // display address
ldr x1,[x21,BT_adresse] // button address
bl XMapWindow
ldr x0,qAdrszTextButton // text address
ldr x1,[x21,BT_adresse] // ident button
mov x2,#18 // position x
mov x3,#18 // position y
bl displayText
b 100f
98:
ldr x0,qAdrszMessErrButtonGC
bl affichageMess
b 100f
99:
ldr x0,qAdrszMessErrButton
bl affichageMess
100:
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrstButton: .quad stButton
qAdrszTextButton: .quad szTextButton
qAdrszMessErrButtonGC: .quad szMessErrButtonGC
qAdrszMessErrButton: .quad szMessErrButton
qButtonMask: .quad ButtonPressMask|ButtonReleaseMask|StructureNotifyMask|ExposureMask|LeaveWindowMask|EnterWindowMask
/******************************************************************/
/* create window input text */
/******************************************************************/
createInputText: // INFO: createInputText
stp x21,lr,[sp,-16]! // save registers
// create button window
mov x0,x28 // display address
mov x1,x27 // ident window
mov x2,50 // X position
mov x3,50 // Y position
mov x4,200 // weight
mov x5,30 // height
mov x6,1 // border
ldr x7,qBlack
ldr x8,qBlanc // background
str x8,[sp,-16]! // argument fot stack
bl XCreateSimpleWindow
add sp,sp,16 // for stack alignement
cmp x0,#0 // error ?
beq 99f
ldr x21,qAdrstInputText
str x0,[x21,Input_adresse] // save ident button
 
// autorisation des saisies
mov x0,x28 // display address
ldr x1,[x21,Input_adresse] // button address
ldr x2,qInputMask // mask
bl XSelectInput
// create Graphic Contexte of button
mov x0,x28 // display address
ldr x1,[x21,Input_adresse] // button ident
mov x2,#0
mov x3,#0
bl XCreateGC
cmp x0,#0
beq 98f
str x0,[x21,Input_GC] // store GC
// display button
mov x0,x28 // display address
ldr x1,[x21,Input_adresse] // button address
bl XMapWindow
 
ldr x6,qAdrsTexteSaisi
 
str x6,[x21,Input_text]
str xzr,[x21,Input_cursor]
 
b 100f
98:
ldr x0,qAdrszMessErrInputGC
bl affichageMess
b 100f
99:
ldr x0,qAdrszMessErrInput
bl affichageMess
100:
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrstInputText: .quad stInputText
qAdrszMessErrInputGC: .quad szMessErrInputGC
qAdrszMessErrInput: .quad szMessErrInput
qInputMask: .quad KeyPressMask|StructureNotifyMask|ExposureMask|LeaveWindowMask|EnterWindowMask
/******************************************************************/
/* create window input text */
/******************************************************************/
createInputValue: // INFO: createInputValue
stp x21,lr,[sp,-16]! // save registers
// create window
mov x0,x28 // display address
mov x1,x27 // ident main window
mov x2,340 // X position
mov x3,50 // Y position
mov x4,50 // weight
mov x5,30 // height
mov x6,1 // border
ldr x7,qBlack
ldr x8,qBlanc // background
str x8,[sp,-16]! // argument fot stack
bl XCreateSimpleWindow
add sp,sp,16 // for stack alignement
cmp x0,#0 // error ?
beq 99f
ldr x21,qAdrstInputValue
str x0,[x21,Input_adresse] // save ident button
 
// autorisation des saisies
mov x0,x28 // display address
ldr x1,[x21,Input_adresse] // button address
ldr x2,qInputMask // mask
bl XSelectInput
// create Graphic Contexte of button
mov x0,x28 // display address
ldr x1,[x21,Input_adresse] // button ident
mov x2,#0
mov x3,#0
bl XCreateGC
cmp x0,#0
beq 98f
str x0,[x21,Input_GC] // store GC
// display button
mov x0,x28 // display address
ldr x1,[x21,Input_adresse] // button address
bl XMapWindow
 
ldr x6,qAdrsValueSaisi
 
str x6,[x21,Input_text]
str xzr,[x21,Input_cursor]
 
b 100f
98:
ldr x0,qAdrszMessErrInputGC
bl affichageMess
b 100f
99:
ldr x0,qAdrszMessErrInput
bl affichageMess
100:
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrstInputValue: .quad stInputValue
qAdrsValueSaisi: .quad sValueSaisi
/******************************************************************/
/* display text on screen */
/******************************************************************/
/* x0 contains the address of text */
/* x1 contains ident window */
/* x2 position X */
/* x3 position Y */
displayText: // INFO: displayText
stp x1,lr,[sp,-16]! // save registers
mov x5,x0 // text address
mov x6,0 // text size
1: // loop compute text size
ldrb w10,[x5,x6] // load text byte
cbz x10,2f // zero -> end
add x6,x6,1 // increment size
b 1b // and loop
2:
mov x0,x28 // display address
mov x4,x3 // position y
mov x3,x2 // position x
mov x2,x26 // GC address
bl XDrawString
100:
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
/******************************************************************/
/* erase text on screen */
/******************************************************************/
/* x0 contains the address of text */
/* x1 window ident */
/* x2 position x */
/* x3 position y */
eraseText1: // INFO: eraseText1
stp x1,lr,[sp,-16]! // save registers
mov x5,x0 // text address
mov x6,0 // text size
1: // loop compute text size
ldrb w10,[x5,x6] // load text byte
cbz x10,2f // zero -> end
add x6,x6,1 // increment size
b 1b // and loop
2:
mov x0,x28 // display address
mov x4,x3
mov x3,x2
mov x2,x25 // GC1 address
bl XDrawString
100:
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
/******************************************************************/
/* events clic mouse button */
/******************************************************************/
/* x0 contains the address of event */
evtButtonMouse: // INFO: evtButtonMouse
stp x20,lr,[sp,-16]! // save registers
ldr x10,[x0,XBE_window] // windows of event
ldr x11,qAdrstButton // load button ident
ldr x12,[x11,BT_adresse]
cmp x10,x12 // equal ?
bne 100f // no
ldr x20,qAdrptMessage // first entry
ldr x0,[x20]
cbz x0,1f
mov x1,x27
mov x2,50
mov x3,200
bl eraseText1 // yes erase the text
1:
ldr x1,qAdrstInputText // input text
ldr x1,[x1,Input_text]
ldrb w2,[x1]
cbz w2,100f // no input text
ldr x0,qAdrszMessResult
bl strInsertAtCharInc // insert text at @ character
mov x5,x0
ldr x1,qAdrstInputValue // input text
ldr x0,[x1,Input_text]
bl conversionAtoD // conversion value to decimal
// x0 contains the input value
 
ldr x1,qAdrsZoneConv // and decimal conversion
bl conversion10
mov x0,x5
ldr x1,qAdrsZoneConv
bl strInsertAtCharInc // and insert result at @ character
str x0,[x20] // save message address
mov x1,x27
mov x2,50
mov x3,200
bl displayText // and display new text
 
100:
ldp x20,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrqCounterClic: .quad qCounterClic
qAdrsZoneConv: .quad sZoneConv
qAdrszMessResult: .quad szMessResult
qAdrptMessage: .quad ptMessage
 
/******************************************************************/
/* display input area */
/******************************************************************/
/* x0 contains area structure */
displayInput: // INFO: displayInput
stp x1,lr,[sp,-16]! // save registers
mov x10,x0 // save structure
ldr x0,[x10,Input_text] // text
ldr x6,[x10,Input_cursor] // position curseur
cbz x6,1f // if zero no text
mov x0,x28 // display address
ldr x1,[x10,Input_adresse] // ident window
ldr x2,[x10,Input_GC] // GC address
mov x3,0 // position x
mov x4,YPOSTEXTINPUT // position y
ldr x5,[x10,Input_text] // text
bl XDrawString
1: // display cursor
mov x0,x28 // Display address
ldr x1,[x10,Input_adresse] // ident window
ldr x2,[x10,Input_GC] // GC address
ldr x3,[x10,Input_cursor] // position x
mov x10,FONTSIZE
mul x3,x3,x10
mov x4,YPOSTEXTINPUT // position y
ldr x5,qAdrszCursor // cursor text
mov x6,1 // length
bl XDrawString
100:
ldp x1,lr,[sp],16 // restaur 2 registers
ret // return to address lr x30
qAdrszCursor: .quad szCursor
/********************************************************/
/* File Include fonctions */
/********************************************************/
/* for this file see task include a file in language AArch64 assembly */
.include "../includeARM64.inc"
/*******************************************/
/* Structures */
/********************************************/
/*************************************************/
/* INFO: Structures */
/*********************************************/
/* Display définition */
.struct 0
Disp_ext_data: /* hook for extension to hang data */
.struct Disp_ext_data + 8
Disp_private1:
.struct Disp_private1 + 8
Disp_fd: /* Network socket. */
.struct Disp_fd + 4
Disp_private2:
.struct Disp_private2 + 4
Disp_proto_major_version: /* major version of server's X protocol */
.struct Disp_proto_major_version + 4
Disp_proto_minor_version: /* minor version of servers X protocol */
.struct Disp_proto_minor_version + 4
Disp_vendor: /* vendor of the server hardware OK*/
.struct Disp_vendor + 8
Disp_private3:
.struct Disp_private3 + 8
Disp_private8:
.struct Disp_private8 + 8
Disp_private5:
.struct Disp_private5 + 8
Disp_private6:
.struct Disp_private6 + 8
Disp_resource_alloc:
.struct Disp_resource_alloc + 8
Disp_byte_order: /* screen byte order, LSBFirst, MSBFirst */
.struct Disp_byte_order+ 4
Disp_bitmap_unit: /* padding and data requirements */
.struct Disp_bitmap_unit + 4
Disp_bitmap_pad: /* padding requirements on bitmaps */
.struct Disp_bitmap_pad + 4
Disp_bitmap_bit_order: /* LeastSignificant or MostSignificant */
.struct Disp_bitmap_bit_order + 4
Disp_nformats: /* number of pixmap formats in list */
.struct Disp_nformats + 8
Disp_pixmap_format: /* pixmap format list */
.struct Disp_pixmap_format + 8
Disp_private28:
.struct Disp_private28 + 4
Disp_release: /* release of the server */
.struct Disp_release + 4
Disp_private9:
.struct Disp_private9 + 8
Disp_private10:
.struct Disp_private10 + 8
Disp_qlen: /* Length of input event queue */
.struct Disp_qlen + 8 /* correction dec19 */
Disp_last_request_read: /* seq number of last event read */
.struct Disp_last_request_read + 8
Disp_request: /* sequence number of last request. */
.struct Disp_request + 8
Disp_private11:
.struct Disp_private11 + 8
Disp_private12:
.struct Disp_private12 + 8
Disp_private13:
.struct Disp_private13 + 8
Disp_private14:
.struct Disp_private14 + 8 /* correction Vim */
Disp_max_request_size: /* maximum number 32 bit words in request*/
.struct Disp_max_request_size + 8
Disp_db:
.struct Disp_db + 8 /* correction Vim */
Disp_private15:
.struct Disp_private15 + 8 /* correction Vim */
Disp_display_name: /* "host:display" string used on this connect*/
.struct Disp_display_name + 8
Disp_default_screen: /* default screen for operations */
.struct Disp_default_screen + 4
Disp_nscreens: /* number of screens on this server*/
.struct Disp_nscreens + 4
Disp_screens: /* pointer to list of screens */
.struct Disp_screens + 8
Disp_motion_buffer: /* size of motion buffer */
.struct Disp_motion_buffer + 8
Disp_private16:
.struct Disp_private16 + 8
Disp_min_keycode: /* minimum defined keycode */
.struct Disp_min_keycode + 4
Disp_max_keycode: /* maximum defined keycode */
.struct Disp_max_keycode + 4
Disp_private17:
.struct Disp_private17 + 8
Disp_private18:
.struct Disp_private18 + 8
Disp_private19:
.struct Disp_private19 + 8
Disp_xdefaults: /* contents of defaults from server */
.struct Disp_xdefaults + 8
Disp_fin:
/*****************************************/
/* Screen définition */
.struct 0
Screen_ext_data: /* hook for extension to hang data */
.struct Screen_ext_data + 8
Screen_Xdisplay: /* back pointer to display structure */
.struct Screen_Xdisplay + 8
Screen_root: /* Root window id. */
.struct Screen_root + 8
Screen_width:
.struct Screen_width + 4
Screen_height:
.struct Screen_height + 4
Screen_mwidth: /* width and height of in millimeters */
.struct Screen_mwidth + 4
Screen_mheight:
.struct Screen_mheight + 4
Screen_ndepths: /* number of depths possible */
.struct Screen_ndepths + 8
Screen_depths: /* list of allowable depths on the screen */
.struct Screen_depths + 8
Screen_root_depth: /* bits per pixel */
.struct Screen_root_depth + 8
Screen_root_visual: /* root visual */
.struct Screen_root_visual + 8
Screen_default_gc: /* GC for the root root visual */
.struct Screen_default_gc + 8
Screen_cmap: /* default color map */
.struct Screen_cmap + 8
Screen_white_pixel:
.struct Screen_white_pixel + 8
Screen_black_pixel:
.struct Screen_black_pixel + 8
Screen_max_maps: /* max and min color maps */
.struct Screen_max_maps + 4
Screen_min_maps:
.struct Screen_min_maps + 4
Screen_backing_store: /* Never, WhenMapped, Always */
.struct Screen_backing_store + 8
Screen_save_unders:
.struct Screen_save_unders + 8
Screen_root_input_mask: /* initial root input mask */
.struct Screen_root_input_mask + 8
Screen_fin:
/**********************************************/
/* Button structure */
.struct 0
BT_cbdata:
.struct BT_cbdata + 8
BT_adresse:
.struct BT_adresse + 8
BT_GC:
.struct BT_GC + 8
BT_Font:
.struct BT_Font + 8
BT_fin:
/****************************************/
/* Input text structure */
.struct 0
 
Input_adresse:
.struct Input_adresse + 8
Input_GC:
.struct Input_GC + 8
Input_text:
.struct Input_text + 8
Input_cursor:
.struct Input_cursor + 8
Input_Font:
.struct Input_Font + 8
Input_fin:
/***************************************************/
/* structure XButtonEvent */
.struct 0
XBE_type: //event type
.struct XBE_type + 8
XBE_serial: // No last request processed server */
.struct XBE_serial + 8
XBE_send_event: // true if this came from a SendEvent request */
.struct XBE_send_event + 8
XBE_display: // Display the event was read from
.struct XBE_display + 8
XBE_window: // "event" window it is reported relative to
.struct XBE_window + 8
XBE_root: // root window that the event occurred on
.struct XBE_root + 8
XBE_subwindow: // child window
.struct XBE_subwindow + 8
XBE_time: // milliseconds
.struct XBE_time + 8
XBE_x: // pointer x, y coordinates in event window
.struct XBE_x + 8
XBE_y:
.struct XBE_y + 8
XBE_x_root: // coordinates relative to root
.struct XBE_x_root + 8
XBE_y_root:
.struct XBE_y_root + 8
XBE_state: // key or button mask
.struct XBE_state + 8
XBE_button: // detail
.struct XBE_button + 8
XBE_same_screen: // same screen flag
.struct XBE_same_screen + 8
XBE_fin:
/***************************************************/
/* structure XAnyEvent */
.struct 0
XAny_type:
.struct XAny_type + 8
XAny_serial:
.struct XAny_serial + 8 /* # of last request processed by server */
XAny_send_event:
.struct XAny_send_event + 8 /* true if this came from a SendEvent request */
XAny_display:
.struct XAny_display + 8 /* Display the event was read from */
XAny_window:
.struct XAny_window + 8 /* window on which event was requested in event mask */
Xany_fin:
/****************************************/
/* structure de type XWindowChanges */
.struct 0
XWCH_x:
.struct XWCH_x + 4
XWCH_y:
.struct XWCH_y + 4
XWCH_width:
.struct XWCH_width + 4
XWCH_height:
.struct XWCH_height + 4
XWCH_border_width:
.struct XWCH_border_width + 4
XWCH_sibling:
.struct XWCH_sibling + 4
XWCH_stack_mode:
.struct XWCH_stack_mode + 4
XWCH_fin:
</syntaxhighlight>
 
=={{header|Ada}}==
{{libheader|GTK|GtkAda}}
{{libheader|GtkAda}}
<langsyntaxhighlight lang="ada">with Gtk.Button; use Gtk.Button;
with Gtk.GEntry; use Gtk.GEntry;
with Gtk.Label; use Gtk.Label;
Line 18 ⟶ 1,131:
procedure Graphic_Input is
Window : Gtk_Window;
Grid : Gtk_TableGtk_Tnetable;
Label : Gtk_Label;
Message : Gtk_Label;
Line 85 ⟶ 1,198:
Gtk.Main.Main;
end Graphic_Input;</langsyntaxhighlight>
 
=={{header|AppleScript}}==
<langsyntaxhighlight lang="applescript">set input to text returned of (display dialog "Enter text:" default answer "")</langsyntaxhighlight>
<langsyntaxhighlight lang="applescript">set input to text returned of (display dialog "Enter a number:" default answer "") as integer</langsyntaxhighlight>
 
=={{header|AutoHotkey}}==
===InputBox===
<langsyntaxhighlight AutoHotkeylang="autohotkey">InputBox, String, Input, Enter a string:
InputBox, Int, Input, Enter an int:
Msgbox, You entered "%String%" and "%Int%"</langsyntaxhighlight>
===Gui Edit===
<langsyntaxhighlight AutoHotkeylang="autohotkey">Gui, Add, Text,, String:
Gui, Add, Text,, Int:
Gui, Add, Button, gGo, Go!
Line 109 ⟶ 1,222:
Msgbox, You entered "%String%" and "%Int%"
ExitApp
Return</langsyntaxhighlight>
 
=={{header|BaCon}}==
Requires BaCon version 4.0.1 or higher, using GTK3.
<syntaxhighlight lang="bacon">OPTION GUI TRUE
PRAGMA GUI gtk3
 
DECLARE text TYPE STRING
DECLARE data TYPE FLOATING
 
gui = GUIDEFINE(" \
{ type=WINDOW name=window callback=delete-event title=\"Rosetta Code\" width-request=300 } \
{ type=BOX name=box parent=window orientation=GTK_ORIENTATION_VERTICAL } \
{ type=ENTRY name=entry parent=box margin=4 callback=activate } \
{ type=SPIN_BUTTON name=spin parent=box margin=4 numeric=TRUE } \
{ type=BUTTON_BOX name=bbox parent=box } \
{ type=BUTTON name=button parent=bbox margin=4 callback=clicked label=\"Exit\" }")
 
CALL GUISET(gui, "spin", "adjustment", gtk_adjustment_new(75000, 0, 100000, 1, 1, 0))
 
REPEAT
event$ = GUIEVENT$(gui)
UNTIL event$ = "button" OR event$ = "window"
 
CALL GUIGET(gui, "entry", "text", &text)
PRINT text FORMAT "Entered: %s\n"
 
CALL GUIGET(gui, "spin", "value", &data)
PRINT data FORMAT "Entered: %g\n"</syntaxhighlight>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"WINLIB2"
INSTALL @lib$+"WINLIB5"
ES_NUMBER = 8192
Line 137 ⟶ 1,278:
PRINT "String = """ $$buffer% """"
PRINT "Number = " ; number%
ENDPROC</langsyntaxhighlight>
 
=={{header|C}}==
{{libheader|GTK}}
<langsyntaxhighlight lang="c">#include <gtk/gtk.h>
 
void ok_hit(GtkButton *o, GtkWidget **w)
Line 214 ⟶ 1,355:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|C++}}==
Line 221 ⟶ 1,362:
task.h
</pre>
<langsyntaxhighlight lang="cpp">#ifndef TASK_H
#define TASK_H
 
Line 245 ⟶ 1,386:
} ;
 
#endif</langsyntaxhighlight>
<pre>
task.cpp
</pre>
<langsyntaxhighlight lang="cpp">#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
Line 276 ⟶ 1,417:
entryLayout->addLayout( lowerpart ) ;
setLayout( entryLayout ) ;
}</langsyntaxhighlight>
<pre>
main.cpp
</pre>
<langsyntaxhighlight lang="cpp">#include <QApplication>
#include "task.h"
 
Line 288 ⟶ 1,429:
theWidget.show( ) ;
return app.exec( ) ;
}</langsyntaxhighlight>
 
 
 
=={{header|Clojure}}==
Line 296 ⟶ 1,435:
Pretty much a straight port of the code for Java.
 
<langsyntaxhighlight Clojurelang="clojure">(import 'javax.swing.JOptionPane)
(let [number (-> "Enter an Integer"
JOptionPane/showInputDialog
Integer/parseInt)
string (JOptionPane/showInputDialog "Enter a String")]
[number string])</langsyntaxhighlight>
 
=={{header|Common Lisp}}==
Line 310 ⟶ 1,449:
Prompt for a string:
 
<langsyntaxhighlight lang="lisp">(capi:prompt-for-string "Enter a string:")</langsyntaxhighlight>
 
Repeatedly prompt for an integer until either the user presses 'Cancel' (instead of 'OK') or the integer is 75,000.
 
<langsyntaxhighlight lang="lisp">(do ((number 0) (okp t))
((or (not okp) (= 75000 number)))
(multiple-value-setq (number okp)
(capi:prompt-for-integer "Enter an integer:")))</langsyntaxhighlight>
 
Alternatively, display a prompt where the 'OK' button will not be enabled until the input is 75,000:
 
<langsyntaxhighlight lang="lisp">(capi:prompt-for-integer "Enter an integer:"
:ok-check #'(lambda (n) (= n 75000)))</langsyntaxhighlight>
 
And a version which displays one prompt with an area for a string and an area for an integer, and only enables the 'OK' button when the integer is 75,000.
 
First, define an interface with the text-areas:
<langsyntaxhighlight lang="lisp">(capi:define-interface string/integer-prompt () ()
(:panes
(string-pane
Line 339 ⟶ 1,478:
(main
capi:column-layout
'(string-pane integer-pane))))</langsyntaxhighlight>
 
Then a function to extract the string and integer:
<langsyntaxhighlight lang="lisp">(defun string/integer-prompt-value (pane)
(with-slots (string-pane integer-pane) pane
(let* ((string (capi:text-input-pane-text string-pane))
Line 348 ⟶ 1,487:
(integer (when (every 'digit-char-p integer-string)
(parse-integer integer-string :junk-allowed t))))
(values (cons string integer)))))</langsyntaxhighlight>
 
Finally, display a prompt using the defined function to extract a value, and an 'ok-check' to ensure that the integer value is 75,000.
<langsyntaxhighlight lang="lisp">(defun do-prompting ()
(capi:popup-confirmer
(make-instance 'string/integer-prompt)
"Enter some values:"
:value-function 'string/integer-prompt-value
:ok-check #'(lambda (result) (eql (cdr result) 75000))))</langsyntaxhighlight>
 
=={{header|Dart}}==
{{libheader|Flutter}}
 
Displays two text fields, a button and an output label, copy paste it into dartpad for viewing! - https://dartpad.github.io
 
<syntaxhighlight lang="javascript">import 'package:flutter/material.dart';
 
main() => runApp( OutputLabel() );
 
class OutputLabel extends StatefulWidget {
@override
_OutputLabelState createState() => _OutputLabelState();
}
 
class _OutputLabelState extends State<OutputLabel> {
String output = "output"; // This will be displayed in an output text field
 
TextEditingController _stringInputController = TextEditingController(); // Allows us to get the text from a text field
TextEditingController _numberInputController = TextEditingController();
 
@override
Widget build( BuildContext context ) {
return MaterialApp(
debugShowCheckedModeBanner: false, // Disable debug banner in top right
home: Scaffold ( // Scaffold provides a layout for the app
body: Center ( // Everything in the center widget will be centered
child: Column ( // All the widgets will be in a column
children: <Widget> [
SizedBox( height: 25 ), // Space between top and text field
 
TextField ( // String input Text Field
controller: _stringInputController, // Add input controller so we can grab text
textAlign: TextAlign.center, // Center text
decoration: InputDecoration( border: OutlineInputBorder(), labelText: 'Enter a string...'), // Border and default text
), // end TextField
 
SizedBox( height: 10 ), // Space between text fields
 
TextField ( // Number input Text Field
controller: _numberInputController, // Add input controller so we can grab text
textAlign: TextAlign.center, // Center text
decoration: InputDecoration( border: OutlineInputBorder(), labelText: 'Enter 75000'), // Border and default text
), // end TextField
 
FlatButton ( // Submit Button
child: Text('Submit Data'), // Button Text
color: Colors.blue[400] // button color
onPressed: () { // On pressed Callback for button
setState( () {
output = ''; // Reset output
 
int number; // Int to store number in
var stringInput = _stringInputController.text ?? ''; // Get the input from the first field, if it is null set it to an empty string
 
var numberString = _numberInputController.text ?? ''; // Get the input from the second field, if it is null set it to an empty string
 
if ( stringInput == '') { // If first field is empty
output = 'Please enter something in field 1\n';
return;
}
 
if (_numberInputController.text == '') { // If second field is empty
output += 'Please enter something in field 2';
return;
} else { // If we got an input in the second field
 
try {
number = int.parse( numberString ); // Parse numberString into an int
 
if ( number == 75000 )
output = 'text output: $stringInput\nnumber: $number'; // Grabs the text from the input controllers and changes the string
else
output = '$number is not 75000!';
 
} on FormatException { // If a number is not entered in second field
output = '$numberString is not a number!';
}
 
}
});
}
), // End FlatButton
 
Text( output ) // displays output
 
]
)
)
)
);
}
}
</syntaxhighlight>
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">program UserInputGraphical;
 
{$APPTYPE CONSOLE}
Line 378 ⟶ 1,613:
ShowMessage('Invalid entry: ' + s);
until lIntegerValue = 75000;
end.</langsyntaxhighlight>
 
=={{header|Frink}}==
Note that the code for getting user input is the same in graphical mode as in text mode. If Frink is running in a graphical mode, it will produce graphical inputs. If running in text mode, it will take input from stdin.
<langsyntaxhighlight lang="frink">
s = input["Enter a string: "]
i = parseInt[input["Enter an integer: "]]
</syntaxhighlight>
</lang>
 
Frink can also produce multiple-field input GUIs. The following works in text mode and in graphical mode, and produces a multi-field input dialog (in Swing, AWT, and Android):
 
<langsyntaxhighlight lang="frink">
[s,i] = input["Dialog title", ["Enter a string", "Enter an integer"]]
i = parseInt[i]
</syntaxhighlight>
</lang>
More information about [http://futureboy.us/frinkdocs/index.html#MultiInput Frink's multi-input], including specifying default values.
 
=={{header|Gambas}}==
<langsyntaxhighlight lang="gambas">hTextBox As TextBox
hValueBox As ValueBox
hLabel As Label
Line 431 ⟶ 1,666:
TextBox1_Change
End</langsyntaxhighlight>
 
'''[http://cogier.com/gambas/User_input-Graphical.png Click here for a picture of the running program]'''
Line 437 ⟶ 1,672:
=={{header|Go}}==
{{libheader|gotk3}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 533 ⟶ 1,768:
window.ShowAll()
gtk.Main()
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
Line 540 ⟶ 1,775:
 
Solution:
<langsyntaxhighlight lang="groovy">import javax.swing.JOptionPane
 
def number = JOptionPane.showInputDialog ("Enter an Integer") as Integer
Line 546 ⟶ 1,781:
 
assert number instanceof Integer
assert string instanceof String</langsyntaxhighlight>
 
=={{header|Haskell}}==
Using {{libheader|gtk}} from [http://hackage.haskell.org/packages/hackage.html HackageDB]
<langsyntaxhighlight lang="haskell">import Graphics.UI.Gtk
import Control.Monad
 
Line 610 ⟶ 1,845:
let mesg = "You entered \"" ++ txt ++ "\""
msgid <- statusbarPush stk id mesg
return ()</langsyntaxhighlight>
Run in GHCi:
<syntaxhighlight lang ="haskell">*Main> main</langsyntaxhighlight>
 
=={{header|HicEst}}==
<langsyntaxhighlight lang="hicest">CHARACTER string*100
 
DLG(Edit=string, Edit=num_value, Button='&OK', TItle='Enter 75000 for num_value')
WRITE(Messagebox, Name) "You entered", string, num_value </langsyntaxhighlight>
 
=={{header|Icon}} and {{header|Unicon}}==
Unicon can open a window directly with ''open''.
 
<langsyntaxhighlight Iconlang="icon">procedure main()
WOpen("size=800,800") | stop("Unable to open window")
WWrite("Enter a string:")
Line 637 ⟶ 1,872:
end
 
link graphics</langsyntaxhighlight>
 
{{libheader|Icon Programming Library}}
[http://www.cs.arizona.edu/icon/library/src/procs/graphics.icn graphics.icn provides WOpen]
 
=={{header|J}}==
'''J 8.x'''
<langsyntaxhighlight lang="j">SIMPLEGUI=: noun define
pc simpleGui;
cc IntegerLabel static;cn "Enter the integer 75000";
Line 669 ⟶ 1,904:
)
 
simpleGui_run''</langsyntaxhighlight>
 
'''J 6.x'''
A revision of the script posted at the [[Simple Windowed Application#J|Simple Windowed Application]]
 
<langsyntaxhighlight lang="j">SIMPLEGUI=: noun define
pc simpleGui;
xywh 136 39 44 12;cc accept button;cn "Accept";
Line 706 ⟶ 1,941:
 
simpleGui_run''
</syntaxhighlight>
</lang>
 
The program stores the values entered as the variables <code>simpleGui_text</code> and <code>simpleGui_integer</code>.
Line 712 ⟶ 1,947:
=={{header|Java}}==
{{libheader|Swing}}
<langsyntaxhighlight lang="java">import javax.swing.*;
 
public class GetInputSwing {
Line 720 ⟶ 1,955:
String string = JOptionPane.showInputDialog ("Enter a String");
}
}</langsyntaxhighlight>
 
=={{header|JavaScript}}==
{{works with|FireFox}} or any JavaScript-enabled browser
<langsyntaxhighlight lang="javascript">var str = prompt("Enter a string");
var value = 0;
while (value != 75000) {
value = parseInt( prompt("Enter the number 75000") );
}</langsyntaxhighlight>
 
 
=={{header|Julia}}==
<langsyntaxhighlight lang="julia">using Gtk
 
function twoentrywindow()
Line 763 ⟶ 1,997:
 
twoentrywindow()
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1
 
import javax.swing.JOptionPane
Line 774 ⟶ 2,008:
val number = JOptionPane.showInputDialog("Enter 75000").toInt()
} while (number != 75000)
}</langsyntaxhighlight>
 
=={{header|LabVIEW}}==
{{VI snippet}}<br/>
[[File:LabVIEW_User_input_Graphical.png]]
 
=={{header|Liberty BASIC}}==
<langsyntaxhighlight lang="lb">' [RC] User input/graphical
 
' Typical LB graphical input/output example.This shows how LB takes user input.
Line 827 ⟶ 2,062:
[quit]
close #w
end</langsyntaxhighlight>
 
=={{header|M2000 Interpreter}}==
===Simple InputBox===
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module CheckIt {
Def aName$="No Name", Num$
Line 847 ⟶ 2,082:
CheckIt "Thank You"
 
</syntaxhighlight>
</lang>
 
===Gui User Form and TextBoxes===
Line 858 ⟶ 2,093:
Form Form1 open modal, so we can close it clicking a square in title bar, or using Alt+d2F4
 
<syntaxhighlight lang="m2000 interpreter">
<lang M2000 Interpreter>
Module Checkit {
Declare Form1 Form
Line 910 ⟶ 2,145:
}
Checkit
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}==
<lang Mathematica>str = InputString["Input a string"]; nb =
InputString["Input a number"]; Print[str, " " , ToString@nb]</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="mathematica">str = InputString["Input a string"]; nb =
InputString["Input a number"]; Print[str, " " , ToString@nb]</syntaxhighlight>
Example usage:
<pre>
->Hello World 75000
</pre>
 
=={{header|Nanoquery}}==
<syntaxhighlight lang="nanoquery">import Nanoquery.Util.Windows
 
// a function to handle the main window closing
def finish(caller, event)
exit
end
 
// create a window
w = new(Window, "Input").setTitle("Input")
w.setSize(320, 190)
w.setHandler(w.closing, finish)
 
// create two labels to go next to the input boxes
stringlabel = new(Label).setParent(w)
intlabel = new(Label).setParent(w)
 
stringlabel.setText("String: "); stringlabel.setPosition(20, 25)
intlabel.setText("Integer: "); intlabel.setPosition(20, 75)
 
// create two textboxes for input
stringbox = new(Textbox).setParent(w)
intbox = new(Textbox).setParent(w)
 
stringbox.setPosition(100, 20); stringbox.setWidth(200); stringbox.setHeight(30)
intbox.setPosition(100, 70); intbox.setWidth(200); intbox.setHeight(30)
 
// a function that handles when the 'done' button is clicked
def done_clicked(caller, event)
global stringbox
global intbox
global w
 
s = stringbox.getText()
i = intbox.getText()
 
try
if int(i) = 75000
println "String: " + s
println "Integer: " + i
exit
else
w.showMessageBox("Please enter 75000 for the integer value")
end
catch
w.showMessageBox("Please enter 75000 for the integer value")
end
end
 
// create the 'done' button
done = new(Button).setParent(w)
 
done.setText("Done"); done.setPosition(250,120)
done.setHandler(done.clicked, done_clicked)
 
// display the window
w.show()</syntaxhighlight>
 
=={{header|NetRexx}}==
{{trans|Java}}
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
import javax.swing.JOptionPane
Line 941 ⟶ 2,233:
 
return
</syntaxhighlight>
</lang>
 
=={{header|NewLISP}}==
<langsyntaxhighlight NewLISPlang="newlisp">; file: input-gui.lsp
; url: http://rosettacode.org/wiki/User_input/Graphical
; author: oofoe 2012-02-02
Line 989 ⟶ 2,281:
 
; No (exit) needed -- guiserver kills program on window close.
</syntaxhighlight>
</lang>
 
[[file:newlisp-input-gui.png]]
 
=={{header|Nim}}==
{{libheader|gintro}}
To input the integer, we use a Gtk SpinBox as is done in the C version.
<syntaxhighlight lang="nim">import strutils
import gintro/[glib, gobject, gtk, gio]
 
type MainWindow = ref object of ApplicationWindow
strEntry: Entry
intEntry: SpinButton
 
#---------------------------------------------------------------------------------------------------
 
proc displayValues(strval: string; intval: int) =
## Display a dialog window with the values entered by the user.
 
let dialog = newDialog()
dialog.setModal(true)
let label1 = newLabel(" String value is “$1”.".format(strval))
label1.setHalign(Align.start)
dialog.contentArea.packStart(label1, true, true, 5)
let msg = " Integer value is $1 which is ".format(intval) &
(if intval == 75000: "right. " else: "wrong (expected 75000). ")
let label2 = newLabel(msg)
dialog.contentArea.packStart(label2, true, true, 5)
discard dialog.addButton("OK", ord(ResponseType.ok))
dialog.showAll()
discard dialog.run()
dialog.destroy()
 
#---------------------------------------------------------------------------------------------------
 
proc onOk(button: Button; window: MainWindow) =
## Callback executed when the OK button has been clicked.
let strval = window.strEntry.text()
let intval = window.intEntry.value().toInt
displayValues(strval, intval)
if intval == 75_000:
window.destroy()
 
#---------------------------------------------------------------------------------------------------
 
proc activate(app: Application) =
## Activate the application.
 
let window = newApplicationWindow(MainWindow, app)
window.setTitle("User input")
 
let content = newBox(Orientation.vertical, 10)
content.setHomogeneous(true)
let grid = newGrid()
grid.setColumnSpacing(30)
let bbox = newButtonBox(Orientation.horizontal)
bbox.setLayout(ButtonBoxStyle.spread)
 
let strLabel = newLabel("Enter some text")
strLabel.setHalign(Align.start)
window.strEntry = newEntry()
grid.attach(strLabel, 0, 0, 1, 1)
grid.attach(window.strEntry, 1, 0, 1, 1)
 
let intLabel = newLabel("Enter 75000")
intLabel.setHalign(Align.start)
window.intEntry = newSpinButtonWithRange(0, 80_000, 1)
grid.attach(intLabel, 0, 1, 1, 1)
grid.attach(window.intEntry, 1, 1, 1, 1)
 
let btnOk = newButton("OK")
 
bbox.add(btnOk)
 
content.packStart(grid, true, true, 0)
content.packEnd(bbox, true, true, 0)
 
window.setBorderWidth(5)
window.add(content)
 
discard btnOk.connect("clicked", onOk, window)
 
window.showAll()
 
#———————————————————————————————————————————————————————————————————————————————————————————————————
 
let app = newApplication(Application, "Rosetta.UserInput")
discard app.connect("activate", activate)
discard app.run()</syntaxhighlight>
 
=={{header|Oz}}==
Line 997 ⟶ 2,375:
Does not allow to close the dialog until 75000 was entered.
Note: "td" is short for "topdown", "lr" for "leftright".
<langsyntaxhighlight lang="oz">functor
import
Application
Line 1,033 ⟶ 2,411:
{System.showInfo "You entered; "#Text#", "#Number}
{Application.exit 0}
end</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use Wx;
 
package MyApp;
Line 1,074 ⟶ 2,452:
package main;
 
MyApp->new->MainLoop;</langsyntaxhighlight>
 
=={{header|Perl 6}}==
{{libheader|GTK}}
<lang perl6>use GTK::Simple;
use GTK::Simple::App;
 
my GTK::Simple::App $app .= new( title => 'User Interaction' );
 
$app.border-width = 20;
 
$app.set-content(
GTK::Simple::VBox.new(
my $ = GTK::Simple::Label.new( text => 'Enter a string.' ),
my $str = GTK::Simple::Entry.new,
my $string = GTK::Simple::Label.new,
my $ = GTK::Simple::Label.new( text => 'Enter the number 75000' ),
my $val = GTK::Simple::Entry.new,
my $correct = GTK::Simple::Label.new,
)
);
 
$str.changed.tap: {
$string.text = "You entered: { $str.text }"
}
 
$val.changed.tap: {
$correct.text = "That's { 'not' unless $val.text ~~ / ^^ <ws> 75000 <ws> $$ / } 75000!"
}
 
$app.run;</lang>
 
=={{header|Phix}}==
{{libheader|pGUIPhix/basics}}
{{libheader|Phix/pGUI}}
<lang Phix>--
<!--<syntaxhighlight lang="phix">(phixonline)-->
-- demo\rosetta\User_Input_Graphical.exw
<span style="color: #000080;font-style:italic;">-- demo\rosetta\User_Input_Graphical.exw</span>
--
<span style="color: #008080;">include</span> <span style="color: #000000;">pGUI</span><span style="color: #0000FF;">.</span><span style="color: #000000;">e</span>
include pGUI.e
 
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">dlg</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">label1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">input1</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">label2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">input2</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">OK</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">Cancel</span>
Ihandle dlg, label1, input1, label2, input2, OK, Cancel
 
<span style="color: #008080;">function</span> <span style="color: #000000;">ok_cb</span><span style="color: #0000FF;">(</span><span style="color: #004080;">Ihandle</span> <span style="color: #000000;">self</span><span style="color: #0000FF;">)</span>
function ok_cb(Ihandle self)
<span style="color: #008080;">if</span> <span style="color: #000000;">self</span><span style="color: #0000FF;">=</span><span style="color: #000000;">OK</span> <span style="color: #008080;">then</span>
if self=OK then
<span style="color: #004080;">string</span> <span style="color: #000000;">in1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">input1</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)</span>
string in1 = IupGetAttribute(input1,"VALUE")
<span style="color: #004080;">integer</span> <span style="color: #000000;">in2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupGetInt</span><span style="color: #0000FF;">(</span><span style="color: #000000;">input2</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"VALUE"</span><span style="color: #0000FF;">)</span>
integer in2 = IupGetInt(input2,"VALUE")
<span style="color: #004080;">string</span> <span style="color: #000000;">msg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">sprintf</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`"%s" and %d`</span><span style="color: #0000FF;">,{</span><span style="color: #000000;">in1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">in2</span><span style="color: #0000FF;">})</span>
string msg = sprintf("\"%s\" and %d",{in1,in2})
<span style="color: #7060A8;">IupMessage</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"You entered"</span><span style="color: #0000FF;">,</span><span style="color: #000000;">msg</span><span style="color: #0000FF;">)</span>
IupMessage("You entered",msg)
<span style="color: #000080;font-style:italic;">-- (return IUP_CONTINUE if unhappy with input)</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
end if
<span style="color: #008080;">return</span> <span style="color: #004600;">IUP_CLOSE</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">function</span>
end function
 
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
function esc_close(Ihandle /*ih*/, atom c)
<span style="color: #000000;">label1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Please enter a string"</span><span style="color: #0000FF;">)</span>
return iff(c=K_ESC?IUP_CLOSE:IUP_CONTINUE)
<span style="color: #000000;">input1</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupText</span><span style="color: #0000FF;">(</span><span style="color: #008000;">`VALUE="a string", EXPAND=HORIZONTAL`</span><span style="color: #0000FF;">)</span>
end function
<span style="color: #000000;">label2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupLabel</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"and the number 75000"</span><span style="color: #0000FF;">)</span>
 
<span style="color: #000000;">input2</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupText</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"VALUE=75000, EXPAND=HORIZONTAL, MASK="</span><span style="color: #0000FF;">&</span><span style="color: #004600;">IUP_MASK_INT</span><span style="color: #0000FF;">)</span>
IupOpen()
<span style="color: #000000;">OK</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupButton</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"OK"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"ACTION"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"ok_cb"</span><span style="color: #0000FF;">))</span>
label1 = IupLabel("Please enter a string")
<span style="color: #000000;">Cancel</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupButton</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"Cancel"</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">"ACTION"</span><span style="color: #0000FF;">,</span> <span style="color: #7060A8;">Icallback</span><span style="color: #0000FF;">(</span><span style="color: #008000;">"ok_cb"</span><span style="color: #0000FF;">))</span>
input1 = IupText("VALUE=\"a string\", EXPAND=HORIZONTAL")
<span style="color: #004080;">sequence</span> <span style="color: #000000;">buttons</span> <span style="color: #0000FF;">=</span> <span style="color: #0000FF;">{</span><span style="color: #7060A8;">IupFill</span><span style="color: #0000FF;">(),</span><span style="color: #000000;">OK</span><span style="color: #0000FF;">,</span><span style="color: #000000;">Cancel</span><span style="color: #0000FF;">,</span><span style="color: #7060A8;">IupFill</span><span style="color: #0000FF;">()}</span>
label2 = IupLabel("and the number 75000")
<span style="color: #004080;">Ihandle</span> <span style="color: #000000;">strbox</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #000000;">label1</span><span style="color: #0000FF;">,</span><span style="color: #000000;">input1</span><span style="color: #0000FF;">},</span><span style="color: #008000;">"ALIGNMENT=ACENTER, PADDING=5"</span><span style="color: #0000FF;">),</span>
input2 = IupText("VALUE=75000, EXPAND=HORIZONTAL")
<span style="color: #000000;">numbox</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">({</span><span style="color: #000000;">label2</span><span style="color: #0000FF;">,</span><span style="color: #000000;">input2</span><span style="color: #0000FF;">},</span><span style="color: #008000;">"ALIGNMENT=ACENTER, PADDING=5"</span><span style="color: #0000FF;">),</span>
IupSetAttribute(input2,"MASK",IUP_MASK_INT)
<span style="color: #000000;">btnbox</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupHbox</span><span style="color: #0000FF;">(</span><span style="color: #000000;">buttons</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"PADDING=40"</span><span style="color: #0000FF;">),</span>
OK = IupButton("OK", "ACTION", Icallback("ok_cb"))
<span style="color: #000000;">vbox</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupVbox</span><span style="color: #0000FF;">({</span><span style="color: #000000;">strbox</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">numbox</span><span style="color: #0000FF;">,</span> <span style="color: #000000;">btnbox</span><span style="color: #0000FF;">},</span> <span style="color: #008000;">"MARGIN=5x5"</span><span style="color: #0000FF;">)</span>
Cancel = IupButton("Cancel", "ACTION", Icallback("ok_cb"))
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
dlg = IupDialog(IupVbox({IupHbox({label1,input1},"ALIGNMENT=ACENTER, PADDING=5"),
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">btnbox</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"NORMALIZESIZE"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"BOTH"</span><span style="color: #0000FF;">)</span>
IupHbox({label2,input2},"ALIGNMENT=ACENTER, PADDING=5"),
<span style="color: #7060A8;">IupSetAttribute</span><span style="color: #0000FF;">(</span><span style="color: #000000;">vbox</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"GAP"</span><span style="color: #0000FF;">,</span><span style="color: #008000;">"5"</span><span style="color: #0000FF;">)</span>
IupHbox({IupFill(),OK,Cancel,IupFill()},"PADDING=15")},
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
"GAP=5,MARGIN=5x5"))
<span style="color: #000000;">dlg</span> <span style="color: #0000FF;">=</span> <span style="color: #7060A8;">IupDialog</span><span style="color: #0000FF;">(</span><span style="color: #000000;">vbox</span><span style="color: #0000FF;">,</span> <span style="color: #008000;">`TITLE="User Input/Graphical"`</span><span style="color: #0000FF;">)</span>
IupSetAttribute(dlg,"TITLE","User Input/Graphical")
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
IupSetCallback(dlg, "K_ANY", Icallback("esc_close"))
<span style="color: #008080;">if</span> <span style="color: #7060A8;">platform</span><span style="color: #0000FF;">()!=</span><span style="color: #004600;">JS</span> <span style="color: #008080;">then</span>
IupDestroy(IupNormalizer({OK,Cancel},"NORMALIZE=BOTH"))
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
IupShow(dlg)
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
IupMainLoop()
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
IupClose()</lang>
<!--</syntaxhighlight>-->
 
=={{header|PicoLisp}}==
<syntaxhighlight lang="picolisp">(and
<lang PicoLisp>(and
(call 'sh "-c"
(pack
Line 1,159 ⟶ 2,508:
(tmp "dlg") ) )
(split (in (tmp "dlg") (line)) "^I")
(cons (pack (car @)) (format (cadr @))) )</langsyntaxhighlight>
Output:
<pre>-> ("Hello world" . 12345)</pre>
Line 1,165 ⟶ 2,514:
=={{header|PowerBASIC}}==
 
<langsyntaxhighlight lang="powerbasic">FUNCTION PBMAIN () AS LONG
result$ = INPUTBOX$("Enter a string.")
MSGBOX result$
Line 1,178 ⟶ 2,527:
END IF
LOOP
END FUNCTION</langsyntaxhighlight>
 
=={{header|PowerShell}}==
Line 1,188 ⟶ 2,537:
[[File:UserInputGraphical.png]]
 
<langsyntaxhighlight PowerShelllang="powershell">#region Define the Windows Form
[Void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
 
Line 1,285 ⟶ 2,634:
$f = $Form1.ShowDialog()
if ( $f -eq [System.Windows.Forms.DialogResult]::Cancel ) { "User selected Cancel" }
else { "User entered `"{0}`" for the text and {1} for the number" -f $txtInputText.Text, $txtInputNumber.Text }</langsyntaxhighlight>
 
=={{header|Processing}}==
{{trans|Java}}
{{libheader|Swing}}
 
<syntaxhighlight lang="java">import javax.swing.JOptionPane;
 
int number = int(JOptionPane.showInputDialog ("Enter an Integer"));
println(number);
String string = JOptionPane.showInputDialog ("Enter a String");
println(string);</syntaxhighlight>
 
==={{header|Processing Python mode}}===
{{trans|Processing}}
{{libheader|Swing}}
 
<syntaxhighlight lang="python">from javax.swing import JOptionPane
 
def to_int(n, default=0):
try:
return int(n)
except ValueError:
return default
 
number = to_int(JOptionPane.showInputDialog ("Enter an Integer"))
println(number)
 
a_string = JOptionPane.showInputDialog ("Enter a String")
println(a_string)</syntaxhighlight>
 
=={{header|PureBasic}}==
<langsyntaxhighlight PureBasiclang="purebasic">string$=InputRequester("Some Title","Enter a string","")
variable=Val(InputRequester("Some other Title","Enter a Number","75000"))</langsyntaxhighlight>
 
=={{header|Python}}==
Line 1,295 ⟶ 2,674:
 
{{libheader|Tkinter}}
<langsyntaxhighlight lang="python">import Tkinter,tkSimpleDialog
 
root = Tkinter.Tk()
Line 1,301 ⟶ 2,680:
 
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
string = tkSimpleDialog.askstring("String", "Enter a String")</lang>
</syntaxhighlight>
 
{{works with|Python|3.7}}
 
{{libheader|Tkinter}}
<syntaxhighlight lang="python">import tkinter
import tkinter.simpledialog as tks
root = tkinter.Tk()
root.withdraw()
number = tks.askinteger("Integer", "Enter a Number")
string = tks.askstring("String", "Enter a String")
 
tkinter.messagebox.showinfo("Results", f"Your input:\n {number} {string}")
</syntaxhighlight>
 
=={{header|Quackery}}==
{{trans|Python}}
<syntaxhighlight lang="quackery">$ \
import tkinter
import tkinter.simpledialog as tks
root = tkinter.Tk()
root.withdraw()
to_stack(tks.askinteger("Integer", "Enter a Number"))
string_to_stack(tks.askstring("String", "Enter a String"))
\ python
swap echo cr echo$</syntaxhighlight>
 
=={{header|R}}==
<syntaxhighlight lang="r">
<lang R>
library(gWidgets)
options(guiToolkit="RGtk2") ## using gWidgtsRGtk2
Line 1,325 ⟶ 2,736:
gmessage("You failed this simple task", parent=w)
})
</syntaxhighlight>
</lang>
 
=={{header|Racket}}==
 
<syntaxhighlight lang="racket">
<lang Racket>
#lang racket
(require racket/gui)
Line 1,339 ⟶ 2,750:
(message-box "Hi" (format "You entered: ~a"
(or (string->number n) "bogus text")))
</syntaxhighlight>
</lang>
 
=={{header|Raku}}==
(formerly Perl 6)
{{libheader|GTK}}
<syntaxhighlight lang="raku" line>use GTK::Simple;
use GTK::Simple::App;
 
my GTK::Simple::App $app .= new( title => 'User Interaction' );
 
$app.border-width = 20;
 
$app.set-content(
GTK::Simple::VBox.new(
my $ = GTK::Simple::Label.new( text => 'Enter a string.' ),
my $str = GTK::Simple::Entry.new,
my $string = GTK::Simple::Label.new,
my $ = GTK::Simple::Label.new( text => 'Enter the number 75000' ),
my $val = GTK::Simple::Entry.new,
my $correct = GTK::Simple::Label.new,
)
);
 
$str.changed.tap: {
$string.text = "You entered: { $str.text }"
}
 
$val.changed.tap: {
$correct.text = "That's { 'not' unless $val.text ~~ / ^^ <ws> 75000 <ws> $$ / } 75000!"
}
 
$app.run;</syntaxhighlight>
 
=={{header|Rascal}}==
<langsyntaxhighlight lang="rascal">import vis::Render;
import vis::Figure;
 
Line 1,355 ⟶ 2,797:
text(str(){return " <integer == "75000" ? "Correct" : "Wrong">";})];
render(grid([row1, row2]));
}</langsyntaxhighlight>
 
Output:
Line 1,365 ⟶ 2,807:
[[File:Useringui_rebol.png]]
 
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Graphical User Input"
URL: http://rosettacode.org/wiki/User_Input_-_graphical
Line 1,422 ⟶ 2,864:
show [si ni] ; Repainting multiple objects at once.
]
]</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 1,429 ⟶ 2,871:
In addition, it checks for errors such as no string entered (or it is blanks or null), and
it verifies that the correct number has been entered.
<langsyntaxhighlight lang="rexx">/*REXX pgm prompts (using the OS GUI) for a string & then prompts for a specific number.*/
#= 75000 #= 75000 /*the number that must be entered. */
x=
string=
N=
nubber=
do while x=' '; say do while string=' ' /*string can't be blanks or null string*/
say 'Please enter a string: say'
parse pull x
say 'Please enter a string: '
if x='' then say '***error*** No string parse pull stringentered.'
end /*while x···*/
if string='' then say '***error*** No string entered.'
end /*while string···*/
 
do while N\=#; say do while number\=# /*the number (belwowbelow) may be ill formed.*/
say 'Please enter the number:' say#
parse pull N
say 'Please enter the number:' #
if datatype(N, 'N') then N= N / 1 parse pull /*normalize the number: 007 4.0 +2 */
if N\=# then if datatype(number,say 'N')***error*** thenThe number= numberis /not 1correct: ' /*normalize number*/N.
end /*while N···*/
if number\=# then say '***error*** The number is not correct: ' number
say
end /*while number···*/
say 'The string entered is:' x /*echo [↓] echothe values (string &and number). */
say 'The number entered is:' N /*stick a fork in it, we're all done. */</syntaxhighlight><br><br>
say 'The string entered is:' string
say 'The number entered is:' number
/*stick a fork in it, we're all done. */</lang><br><br>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
Load "guilib.ring"
 
Line 1,497 ⟶ 2,936:
num2 = number(temp2)
if num2 = 75000 label2{settext("OK")} else label2{settext("NOT OK")} ok
</syntaxhighlight>
</lang>
Output:
 
Line 1,506 ⟶ 2,945:
 
{{libheader|Ruby/Tk}}
<langsyntaxhighlight lang="ruby">require 'tk'
 
def main
Line 1,544 ⟶ 2,983:
end
 
main</langsyntaxhighlight>
 
{{libheader|Shoes}}
<langsyntaxhighlight lang="ruby">Shoes.app do
string = ask('Enter a string:')
begin
Line 1,553 ⟶ 2,992:
end while number.to_i != 75000
para %Q{you entered the string "#{string}" and the number #{number}}
end</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<syntaxhighlight lang="runbasic">html "<TABLE BORDER=1 BGCOLOR=silver>
<TR><TD colspan=2>Please input a string and a number</TD></TR>
 
<TR><TD align=right>String</TD><TD><input type=text name=str size=18></TD></TR>
<TR><TD align=right>Number</TD><TD><input type=number name=num size=18 value=75000></TD></TR>
 
<TR><TD colspan=2 align=center>"
 
button #go, "Accept", [go]
button #ex, "Exit", [ex]
 
html "</TD></TR></TABLE>"
Wait
 
[go]
print #request get$("str")
print val(#request get$("num"))
wait
 
[ex]
end</syntaxhighlight>
 
=={{header|Scala}}==
{{libheader|Scala}}
<langsyntaxhighlight lang="scala">import swing.Dialog.{Message, showInput}
import scala.swing.Swing
Line 1,568 ⟶ 3,030:
Nil, "ham")
println(responce)
}</langsyntaxhighlight>
 
=={{header|Scratch}}==
Line 1,579 ⟶ 3,041:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var gtk2 = require('Gtk2') -> init;
 
var gui = %s'Gtk2::Builder'.new;
Line 1,760 ⟶ 3,222:
</child>
</object>
</interface></langsyntaxhighlight>
 
=={{header|Standard ML}}==
Works with PolyML
<syntaxhighlight lang="standard ml">open XWindows ;
open Motif ;
 
val store : string list ref = ref [] ;
 
val inputWindow = fn () =>
let
val shell = XtAppInitialise "" "demo" "top" [] [ XmNwidth 320, XmNheight 100 ] ;
val main = XmCreateMainWindow shell "main" [ XmNmappedWhenManaged true ] ;
val enter = XmCreateText main "inputarea" [ XmNeditMode XmSINGLE_LINE_EDIT,
XmNscrollHorizontal false ] ;
val getinp = fn (w,s,t) => ( store := XmTextGetString enter :: !store ; t )
in
(
XtSetCallbacks enter [ (XmNactivateCallback , getinp) ] XmNarmCallback ;
XtManageChild enter ;
XtManageChild main ;
XtRealizeWidget shell
)
end ;
 
inputWindow () ;</syntaxhighlight>
enter text, press enter, delete, enter 75000, press enter, result:
!store ;
List.map Int.fromString (!store) ;
 
val it = ["75000", "That string"]: string list
val it = [SOME 75000, NONE]: int option list
=={{header|Tcl}}==
 
{{libheader|Tk}}
<langsyntaxhighlight lang="tcl"># create entry widget:
pack [entry .e1]
 
# read its content:
set input [.e get]</langsyntaxhighlight>
 
Alternatively, the content of the widget can be tied to a variable:
<langsyntaxhighlight lang="tcl">pack [entry .e1 -textvar input]
 
# show the content at any time by
puts $input</langsyntaxhighlight>
The <tt>-validate</tt> option can be used to test the contents/edits of the widget at any time against any parameters (including testing <tt>string is integer</tt> when the user hits <Return> or such)
 
Line 1,782 ⟶ 3,276:
This program leaves the requested values in the global variables ''s'' and ''n''.
 
<langsyntaxhighlight lang="ti89b">Prgm
Dialog
Title "Rosetta Code"
Line 1,789 ⟶ 3,283:
EndDlog
74999 + n → n
EndPrgm</langsyntaxhighlight>
 
=={{header|VBScript}}==
{{works with|Windows Script Host}}
<langsyntaxhighlight lang="vbscript">strUserIn = InputBox("Enter Data")
Wscript.Echo strUserIn</langsyntaxhighlight>
 
=={{header|Vedit macro language}}==
Line 1,800 ⟶ 3,294:
The value from 2nd field is then converted into numeric value. (Accepts integers or integer expressions.)
 
<langsyntaxhighlight lang="vedit">Dialog_Input_1(1, "`User Input example`,
`??Enter a string `,
`??Enter a number `")</langsyntaxhighlight>
#2 = Num_Eval_Reg(2)
 
Line 1,810 ⟶ 3,304:
 
Alternately, a form could be easily created (using the form designer) to get both values at once, but that is a task almost ''never'' done at runtime, instead being done within the IDE while creating the program.
 
=={{header|Wren}}==
{{libheader|DOME}}
This script echos the string and number entered in the GUI to the terminal.
 
In the case of the number, it keeps requesting input until 75000 is entered and then quits.
<syntaxhighlight lang="wren">import "graphics" for Canvas, Color
import "input" for Keyboard, Clipboard
import "dome" for Window, Process
 
var X = 10
var Y = 28
 
class Main {
construct new() {}
 
init() {
_text = ""
_enterNum = false
Keyboard.handleText = true
Keyboard.textRegion(X, Y, 8, 8)
}
 
update() {
var change = false
if (Keyboard.text.count > 0) {
_text = _text + Keyboard.text
change = true
}
 
// enable backspace key to delete last character entered
if (Keyboard["backspace"].justPressed && _text.count > 0) {
var codePoints = _text.codePoints
codePoints = codePoints.take(codePoints.count - 1)
_text = ""
for (point in codePoints) {
_text = _text + String.fromCodePoint(point)
}
change = true
}
 
// enable return key to terminate input
if (Keyboard["return"].justPressed) {
System.print("'%(_text)' was entered.")
if (!_enterNum) {
_text = ""
_enterNum = true
change = true
} else if (_text == "75000") {
Process.exit()
} else {
_text = ""
change = true
}
}
 
if (change) {
Keyboard.textRegion(X.min(_text.count * 8), Y, 8, 8)
}
}
 
draw(dt) {
Canvas.cls()
Canvas.rect(X, Y, 8, 8, Color.red)
if (!_enterNum) {
Canvas.print("Enter Text and press return:", 10, 10, Color.white)
} else {
Canvas.print("Enter 75000 and press return:", 10, 10, Color.white)
}
Canvas.print(_text, 10, 20, Color.white)
}
}
 
var Game = Main.new()</syntaxhighlight>
 
{{out}}
Sample input/output:
<pre>
'Rosetta' was entered.
'72000' was entered.
'75000' was entered.
</pre>
 
{{omit from|ACL2}}
9,476

edits