User input/Graphical: Difference between revisions

m
→‎{{header|Wren}}: Changed to Wren S/H
(→‎{{header|Processing Python mode}}: int conversion fail-safe)
m (→‎{{header|Wren}}: Changed to Wren S/H)
 
(19 intermediate revisions by 12 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">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program inputWin64.s */
Line 1,107 ⟶ 1,114:
.struct XWCH_stack_mode + 4
XWCH_fin:
</syntaxhighlight>
</lang>
 
=={{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 1,191 ⟶ 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|Arturo}}==
{{libheader|GTK}}
<lang arturo>use ~gui
 
window @mainWindow #{
:title "User Input / Graphical"
:size #(400 300)
 
vbox #{
hbox #{
label "string" #{}
textfield @str "" #{}
}
hbox #{
label "number" #{}
textfield @num "" #{}
}
button "Enter data" #{
:onClick {
print "Got: " + $(str.get) + ", " + $(num.get)
}
}
}
}
 
app @main "UserInput.Graphical" mainWindow #{}
main.run</lang>
 
{{out}}
 
<pre>Got: hello, 75000</pre>
 
=={{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 1,247 ⟶ 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 1,275 ⟶ 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 1,352 ⟶ 1,355:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|C++}}==
Line 1,359 ⟶ 1,362:
task.h
</pre>
<langsyntaxhighlight lang="cpp">#ifndef TASK_H
#define TASK_H
 
Line 1,383 ⟶ 1,386:
} ;
 
#endif</langsyntaxhighlight>
<pre>
task.cpp
</pre>
<langsyntaxhighlight lang="cpp">#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
Line 1,414 ⟶ 1,417:
entryLayout->addLayout( lowerpart ) ;
setLayout( entryLayout ) ;
}</langsyntaxhighlight>
<pre>
main.cpp
</pre>
<langsyntaxhighlight lang="cpp">#include <QApplication>
#include "task.h"
 
Line 1,426 ⟶ 1,429:
theWidget.show( ) ;
return app.exec( ) ;
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
Line 1,432 ⟶ 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 1,446 ⟶ 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 1,475 ⟶ 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 1,484 ⟶ 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}}==
Line 1,499 ⟶ 1,502:
Displays two text fields, a button and an output label, copy paste it into dartpad for viewing! - https://dartpad.github.io
 
<langsyntaxhighlight lang="javascript">import 'package:flutter/material.dart';
 
main() => runApp( OutputLabel() );
Line 1,588 ⟶ 1,591:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">program UserInputGraphical;
 
{$APPTYPE CONSOLE}
Line 1,610 ⟶ 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 1,663 ⟶ 1,666:
TextBox1_Change
End</langsyntaxhighlight>
 
'''[http://cogier.com/gambas/User_input-Graphical.png Click here for a picture of the running program]'''
Line 1,669 ⟶ 1,672:
=={{header|Go}}==
{{libheader|gotk3}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,765 ⟶ 1,768:
window.ShowAll()
gtk.Main()
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
Line 1,772 ⟶ 1,775:
 
Solution:
<langsyntaxhighlight lang="groovy">import javax.swing.JOptionPane
 
def number = JOptionPane.showInputDialog ("Enter an Integer") as Integer
Line 1,778 ⟶ 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 1,842 ⟶ 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 1,869 ⟶ 1,872:
end
 
link graphics</langsyntaxhighlight>
 
{{libheader|Icon Programming Library}}
Line 1,876 ⟶ 1,879:
=={{header|J}}==
'''J 8.x'''
<langsyntaxhighlight lang="j">SIMPLEGUI=: noun define
pc simpleGui;
cc IntegerLabel static;cn "Enter the integer 75000";
Line 1,901 ⟶ 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 1,938 ⟶ 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 1,944 ⟶ 1,947:
=={{header|Java}}==
{{libheader|Swing}}
<langsyntaxhighlight lang="java">import javax.swing.*;
 
public class GetInputSwing {
Line 1,952 ⟶ 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 1,994 ⟶ 1,997:
 
twoentrywindow()
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1
 
import javax.swing.JOptionPane
Line 2,005 ⟶ 2,008:
val number = JOptionPane.showInputDialog("Enter 75000").toInt()
} while (number != 75000)
}</langsyntaxhighlight>
 
=={{header|LabVIEW}}==
Line 2,012 ⟶ 2,015:
 
=={{header|Liberty BASIC}}==
<langsyntaxhighlight lang="lb">' [RC] User input/graphical
 
' Typical LB graphical input/output example.This shows how LB takes user input.
Line 2,059 ⟶ 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 2,079 ⟶ 2,082:
CheckIt "Thank You"
 
</syntaxhighlight>
</lang>
 
===Gui User Form and TextBoxes===
Line 2,090 ⟶ 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 2,142 ⟶ 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>
Line 2,154 ⟶ 2,156:
 
=={{header|Nanoquery}}==
<langsyntaxhighlight Nanoquerylang="nanoquery">import Nanoquery.Util.Windows
 
// a function to handle the main window closing
Line 2,209 ⟶ 2,211:
 
// display the window
w.show()</langsyntaxhighlight>
 
=={{header|NetRexx}}==
{{trans|Java}}
<langsyntaxhighlight NetRexxlang="netrexx">/* NetRexx */
options replace format comments java crossref symbols nobinary
import javax.swing.JOptionPane
Line 2,231 ⟶ 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 2,279 ⟶ 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 2,287 ⟶ 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 2,323 ⟶ 2,411:
{System.showInfo "You entered; "#Text#", "#Number}
{Application.exit 0}
end</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use Wx;
 
package MyApp;
Line 2,364 ⟶ 2,452:
package main;
 
MyApp->new->MainLoop;</langsyntaxhighlight>
 
=={{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 2,419 ⟶ 2,508:
(tmp "dlg") ) )
(split (in (tmp "dlg") (line)) "^I")
(cons (pack (car @)) (format (cadr @))) )</langsyntaxhighlight>
Output:
<pre>-> ("Hello world" . 12345)</pre>
Line 2,425 ⟶ 2,514:
=={{header|PowerBASIC}}==
 
<langsyntaxhighlight lang="powerbasic">FUNCTION PBMAIN () AS LONG
result$ = INPUTBOX$("Enter a string.")
MSGBOX result$
Line 2,438 ⟶ 2,527:
END IF
LOOP
END FUNCTION</langsyntaxhighlight>
 
=={{header|PowerShell}}==
Line 2,448 ⟶ 2,537:
[[File:UserInputGraphical.png]]
 
<langsyntaxhighlight PowerShelllang="powershell">#region Define the Windows Form
[Void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
 
Line 2,545 ⟶ 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}}==
Line 2,551 ⟶ 2,640:
{{libheader|Swing}}
 
<langsyntaxhighlight lang="java">import javax.swing.JOptionPane;
 
int number = int(JOptionPane.showInputDialog ("Enter an Integer"));
println(number);
String string = JOptionPane.showInputDialog ("Enter a String");</lang>
println(string);</syntaxhighlight>
 
==={{header|Processing Python mode}}===
Line 2,561 ⟶ 2,652:
{{libheader|Swing}}
 
<langsyntaxhighlight Pythonlang="python">from javax.swing import JOptionPane
 
def to_int(n, default=0):
Line 2,570 ⟶ 2,661:
 
number = to_int(JOptionPane.showInputDialog ("Enter an Integer"))
println(number)
 
stringa_string = JOptionPane.showInputDialog ("Enter a String")</lang>
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 2,581 ⟶ 2,674:
 
{{libheader|Tkinter}}
<langsyntaxhighlight lang="python">import Tkinter,tkSimpleDialog
 
root = Tkinter.Tk()
Line 2,587 ⟶ 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 2,611 ⟶ 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 2,625 ⟶ 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" perl6line>use GTK::Simple;
use GTK::Simple::App;
 
Line 2,656 ⟶ 2,781:
}
 
$app.run;</langsyntaxhighlight>
 
=={{header|Rascal}}==
<langsyntaxhighlight lang="rascal">import vis::Render;
import vis::Figure;
 
Line 2,672 ⟶ 2,797:
text(str(){return " <integer == "75000" ? "Correct" : "Wrong">";})];
render(grid([row1, row2]));
}</langsyntaxhighlight>
 
Output:
Line 2,682 ⟶ 2,807:
[[File:Useringui_rebol.png]]
 
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Graphical User Input"
URL: http://rosettacode.org/wiki/User_Input_-_graphical
Line 2,739 ⟶ 2,864:
show [si ni] ; Repainting multiple objects at once.
]
]</langsyntaxhighlight>
 
=={{header|REXX}}==
Line 2,746 ⟶ 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 /*the number that must be entered. */
x=
Line 2,764 ⟶ 2,889:
say
say 'The string entered is:' x /*echo the values (string and number. */
say 'The number entered is:' N /*stick a fork in it, we're all done. */</langsyntaxhighlight><br><br>
 
=={{header|Ring}}==
<langsyntaxhighlight lang="ring">
Load "guilib.ring"
 
Line 2,811 ⟶ 2,936:
num2 = number(temp2)
if num2 = 75000 label2{settext("OK")} else label2{settext("NOT OK")} ok
</syntaxhighlight>
</lang>
Output:
 
Line 2,820 ⟶ 2,945:
 
{{libheader|Ruby/Tk}}
<langsyntaxhighlight lang="ruby">require 'tk'
 
def main
Line 2,858 ⟶ 2,983:
end
 
main</langsyntaxhighlight>
 
{{libheader|Shoes}}
<langsyntaxhighlight lang="ruby">Shoes.app do
string = ask('Enter a string:')
begin
Line 2,867 ⟶ 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 2,882 ⟶ 3,030:
Nil, "ham")
println(responce)
}</langsyntaxhighlight>
 
=={{header|Scratch}}==
Line 2,893 ⟶ 3,041:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var gtk2 = require('Gtk2') -> init;
 
var gui = %s'Gtk2::Builder'.new;
Line 3,074 ⟶ 3,222:
</child>
</object>
</interface></langsyntaxhighlight>
 
=={{header|Standard ML}}==
Works with PolyML
<langsyntaxhighlight Standardlang="standard MLml">open XWindows ;
open Motif ;
 
Line 3,101 ⟶ 3,249:
end ;
 
inputWindow () ;</langsyntaxhighlight>
enter text, press enter, delete, enter 75000, press enter, result:
!store ;
Line 3,111 ⟶ 3,259:
 
{{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 3,128 ⟶ 3,276:
This program leaves the requested values in the global variables ''s'' and ''n''.
 
<langsyntaxhighlight lang="ti89b">Prgm
Dialog
Title "Rosetta Code"
Line 3,135 ⟶ 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 3,146 ⟶ 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 3,156 ⟶ 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,479

edits