User input/Graphical: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
m (→{{header|Wren}}: Changed to Wren S/H) |
|||
(18 intermediate revisions by 12 users not shown) | |||
Line 1:
{{task|Text processing
[[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 */
Line 1,107 ⟶ 1,114:
.struct XWCH_stack_mode + 4
XWCH_fin:
</syntaxhighlight>
=={{header|Ada}}==
{{libheader|GTK|GtkAda}}
{{libheader|GtkAda}}
<
with Gtk.GEntry; use Gtk.GEntry;
with Gtk.Label; use Gtk.Label;
Line 1,191 ⟶ 1,198:
Gtk.Main.Main;
end Graphic_Input;</
=={{header|AppleScript}}==
<
<
=={{header|AutoHotkey}}==
===InputBox===
<
InputBox, Int, Input, Enter an int:
Msgbox, You entered "%String%" and "%Int%"</
===Gui Edit===
<
Gui, Add, Text,, Int:
Gui, Add, Button, gGo, Go!
Line 1,247 ⟶ 1,222:
Msgbox, You entered "%String%" and "%Int%"
ExitApp
Return</
=={{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}}
<
INSTALL @lib$+"WINLIB5"
ES_NUMBER = 8192
Line 1,275 ⟶ 1,278:
PRINT "String = """ $$buffer% """"
PRINT "Number = " ; number%
ENDPROC</
=={{header|C}}==
{{libheader|GTK}}
<
void ok_hit(GtkButton *o, GtkWidget **w)
Line 1,352 ⟶ 1,355:
return 0;
}</
=={{header|C++}}==
Line 1,359 ⟶ 1,362:
task.h
</pre>
<
#define TASK_H
Line 1,383 ⟶ 1,386:
} ;
#endif</
<pre>
task.cpp
</pre>
<
#include <QLabel>
#include <QHBoxLayout>
Line 1,414 ⟶ 1,417:
entryLayout->addLayout( lowerpart ) ;
setLayout( entryLayout ) ;
}</
<pre>
main.cpp
</pre>
<
#include "task.h"
Line 1,426 ⟶ 1,429:
theWidget.show( ) ;
return app.exec( ) ;
}</
=={{header|Clojure}}==
Line 1,432 ⟶ 1,435:
Pretty much a straight port of the code for Java.
<
(let [number (-> "Enter an Integer"
JOptionPane/showInputDialog
Integer/parseInt)
string (JOptionPane/showInputDialog "Enter a String")]
[number string])</
=={{header|Common Lisp}}==
Line 1,446 ⟶ 1,449:
Prompt for a string:
<
Repeatedly prompt for an integer until either the user presses 'Cancel' (instead of 'OK') or the integer is 75,000.
<
((or (not okp) (= 75000 number)))
(multiple-value-setq (number okp)
(capi:prompt-for-integer "Enter an integer:")))</
Alternatively, display a prompt where the 'OK' button will not be enabled until the input is 75,000:
<
:ok-check #'(lambda (n) (= n 75000)))</
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:
<
(:panes
(string-pane
Line 1,475 ⟶ 1,478:
(main
capi:column-layout
'(string-pane integer-pane))))</
Then a function to extract the string and integer:
<
(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)))))</
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.
<
(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))))</
=={{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
<
main() => runApp( OutputLabel() );
Line 1,588 ⟶ 1,591:
}
}
</syntaxhighlight>
=={{header|Delphi}}==
<
{$APPTYPE CONSOLE}
Line 1,610 ⟶ 1,613:
ShowMessage('Invalid entry: ' + s);
until lIntegerValue = 75000;
end.</
=={{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.
<
s = input["Enter a string: "]
i = parseInt[input["Enter an integer: "]]
</syntaxhighlight>
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):
<
[s,i] = input["Dialog title", ["Enter a string", "Enter an integer"]]
i = parseInt[i]
</syntaxhighlight>
More information about [http://futureboy.us/frinkdocs/index.html#MultiInput Frink's multi-input], including specifying default values.
=={{header|Gambas}}==
<
hValueBox As ValueBox
hLabel As Label
Line 1,663 ⟶ 1,666:
TextBox1_Change
End</
'''[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}}
<
import (
Line 1,765 ⟶ 1,768:
window.ShowAll()
gtk.Main()
}</
=={{header|Groovy}}==
Line 1,772 ⟶ 1,775:
Solution:
<
def number = JOptionPane.showInputDialog ("Enter an Integer") as Integer
Line 1,778 ⟶ 1,781:
assert number instanceof Integer
assert string instanceof String</
=={{header|Haskell}}==
Using {{libheader|gtk}} from [http://hackage.haskell.org/packages/hackage.html HackageDB]
<
import Control.Monad
Line 1,842 ⟶ 1,845:
let mesg = "You entered \"" ++ txt ++ "\""
msgid <- statusbarPush stk id mesg
return ()</
Run in GHCi:
<syntaxhighlight lang
=={{header|HicEst}}==
<
DLG(Edit=string, Edit=num_value, Button='&OK', TItle='Enter 75000 for num_value')
WRITE(Messagebox, Name) "You entered", string, num_value </
=={{header|Icon}} and {{header|Unicon}}==
Unicon can open a window directly with ''open''.
<
WOpen("size=800,800") | stop("Unable to open window")
WWrite("Enter a string:")
Line 1,869 ⟶ 1,872:
end
link graphics</
{{libheader|Icon Programming Library}}
Line 1,876 ⟶ 1,879:
=={{header|J}}==
'''J 8.x'''
<
pc simpleGui;
cc IntegerLabel static;cn "Enter the integer 75000";
Line 1,901 ⟶ 1,904:
)
simpleGui_run''</
'''J 6.x'''
A revision of the script posted at the [[Simple Windowed Application#J|Simple Windowed Application]]
<
pc simpleGui;
xywh 136 39 44 12;cc accept button;cn "Accept";
Line 1,938 ⟶ 1,941:
simpleGui_run''
</syntaxhighlight>
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}}
<
public class GetInputSwing {
Line 1,952 ⟶ 1,955:
String string = JOptionPane.showInputDialog ("Enter a String");
}
}</
=={{header|JavaScript}}==
{{works with|FireFox}} or any JavaScript-enabled browser
<
var value = 0;
while (value != 75000) {
value = parseInt( prompt("Enter the number 75000") );
}</
=={{header|Julia}}==
<
function twoentrywindow()
Line 1,994 ⟶ 1,997:
twoentrywindow()
</syntaxhighlight>
=={{header|Kotlin}}==
<
import javax.swing.JOptionPane
Line 2,005 ⟶ 2,008:
val number = JOptionPane.showInputDialog("Enter 75000").toInt()
} while (number != 75000)
}</
=={{header|LabVIEW}}==
Line 2,012 ⟶ 2,015:
=={{header|Liberty BASIC}}==
<
' Typical LB graphical input/output example.This shows how LB takes user input.
Line 2,059 ⟶ 2,062:
[quit]
close #w
end</
=={{header|M2000 Interpreter}}==
===Simple InputBox===
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
Def aName$="No Name", Num$
Line 2,079 ⟶ 2,082:
CheckIt "Thank You"
</syntaxhighlight>
===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">
Module Checkit {
Declare Form1 Form
Line 2,142 ⟶ 2,145:
}
Checkit
</syntaxhighlight>
=={{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}}==
<
// a function to handle the main window closing
Line 2,209 ⟶ 2,211:
// display the window
w.show()</
=={{header|NetRexx}}==
{{trans|Java}}
<
options replace format comments java crossref symbols nobinary
import javax.swing.JOptionPane
Line 2,231 ⟶ 2,233:
return
</syntaxhighlight>
=={{header|NewLISP}}==
<
; 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>
[[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".
<
import
Application
Line 2,323 ⟶ 2,411:
{System.showInfo "You entered; "#Text#", "#Number}
{Application.exit 0}
end</
=={{header|Perl}}==
<
package MyApp;
Line 2,364 ⟶ 2,452:
package main;
MyApp->new->MainLoop;</
=={{header|Phix}}==
{{libheader|
{{libheader|Phix/pGUI}}
<!--<syntaxhighlight lang="phix">(phixonline)-->
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<span style="color: #7060A8;">IupOpen</span><span style="color: #0000FF;">()</span>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<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>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<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>
<span style="color: #7060A8;">IupShow</span><span style="color: #0000FF;">(</span><span style="color: #000000;">dlg</span><span style="color: #0000FF;">)</span>
<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>
<span style="color: #7060A8;">IupMainLoop</span><span style="color: #0000FF;">()</span>
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</syntaxhighlight>-->
=={{header|PicoLisp}}==
<syntaxhighlight 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 @))) )</
Output:
<pre>-> ("Hello world" . 12345)</pre>
Line 2,425 ⟶ 2,514:
=={{header|PowerBASIC}}==
<
result$ = INPUTBOX$("Enter a string.")
MSGBOX result$
Line 2,438 ⟶ 2,527:
END IF
LOOP
END FUNCTION</
=={{header|PowerShell}}==
Line 2,448 ⟶ 2,537:
[[File:UserInputGraphical.png]]
<
[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 }</
=={{header|Processing}}==
Line 2,551 ⟶ 2,640:
{{libheader|Swing}}
<
int number = int(JOptionPane.showInputDialog ("Enter an Integer"));
Line 2,557 ⟶ 2,646:
String string = JOptionPane.showInputDialog ("Enter a String");
println(string);</
==={{header|Processing Python mode}}===
Line 2,563 ⟶ 2,652:
{{libheader|Swing}}
<
def to_int(n, default=0):
Line 2,574 ⟶ 2,663:
println(number)
println(
=={{header|PureBasic}}==
<
variable=Val(InputRequester("Some other Title","Enter a Number","75000"))</
=={{header|Python}}==
Line 2,585 ⟶ 2,674:
{{libheader|Tkinter}}
<
root = Tkinter.Tk()
Line 2,591 ⟶ 2,680:
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
string = tkSimpleDialog.askstring("String", "Enter a String")
</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">
library(gWidgets)
options(guiToolkit="RGtk2") ## using gWidgtsRGtk2
Line 2,615 ⟶ 2,736:
gmessage("You failed this simple task", parent=w)
})
</syntaxhighlight>
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket
(require racket/gui)
Line 2,629 ⟶ 2,750:
(message-box "Hi" (format "You entered: ~a"
(or (string->number n) "bogus text")))
</syntaxhighlight>
=={{header|Raku}}==
(formerly Perl 6)
{{libheader|GTK}}
<syntaxhighlight lang="raku"
use GTK::Simple::App;
Line 2,660 ⟶ 2,781:
}
$app.run;</
=={{header|Rascal}}==
<
import vis::Figure;
Line 2,676 ⟶ 2,797:
text(str(){return " <integer == "75000" ? "Correct" : "Wrong">";})];
render(grid([row1, row2]));
}</
Output:
Line 2,686 ⟶ 2,807:
[[File:Useringui_rebol.png]]
<
Title: "Graphical User Input"
URL: http://rosettacode.org/wiki/User_Input_-_graphical
Line 2,743 ⟶ 2,864:
show [si ni] ; Repainting multiple objects at once.
]
]</
=={{header|REXX}}==
Line 2,750 ⟶ 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.
<
#= 75000 /*the number that must be entered. */
x=
Line 2,768 ⟶ 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. */</
=={{header|Ring}}==
<
Load "guilib.ring"
Line 2,815 ⟶ 2,936:
num2 = number(temp2)
if num2 = 75000 label2{settext("OK")} else label2{settext("NOT OK")} ok
</syntaxhighlight>
Output:
Line 2,824 ⟶ 2,945:
{{libheader|Ruby/Tk}}
<
def main
Line 2,862 ⟶ 2,983:
end
main</
{{libheader|Shoes}}
<
string = ask('Enter a string:')
begin
Line 2,871 ⟶ 2,992:
end while number.to_i != 75000
para %Q{you entered the string "#{string}" and the number #{number}}
end</
=={{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}}
<
import scala.swing.Swing
Line 2,886 ⟶ 3,030:
Nil, "ham")
println(responce)
}</
=={{header|Scratch}}==
Line 2,897 ⟶ 3,041:
=={{header|Sidef}}==
<
var gui = %s'Gtk2::Builder'.new;
Line 3,078 ⟶ 3,222:
</child>
</object>
</interface></
=={{header|Standard ML}}==
Works with PolyML
<
open Motif ;
Line 3,105 ⟶ 3,249:
end ;
inputWindow () ;</
enter text, press enter, delete, enter 75000, press enter, result:
!store ;
Line 3,115 ⟶ 3,259:
{{libheader|Tk}}
<
pack [entry .e1]
# read its content:
set input [.e get]</
Alternatively, the content of the widget can be tied to a variable:
<
# show the content at any time by
puts $input</
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,132 ⟶ 3,276:
This program leaves the requested values in the global variables ''s'' and ''n''.
<
Dialog
Title "Rosetta Code"
Line 3,139 ⟶ 3,283:
EndDlog
74999 + n → n
EndPrgm</
=={{header|VBScript}}==
{{works with|Windows Script Host}}
<
Wscript.Echo strUserIn</
=={{header|Vedit macro language}}==
Line 3,150 ⟶ 3,294:
The value from 2nd field is then converted into numeric value. (Accepts integers or integer expressions.)
<
`??Enter a string `,
`??Enter a number `")</
#2 = Num_Eval_Reg(2)
Line 3,160 ⟶ 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}}
|