User input/Graphical: Difference between revisions
m
→{{header|Wren}}: Changed to Wren S/H
m (→{{header|Wren}}: Changed to Wren S/H) |
|||
(One intermediate revision by one other user not shown) | |||
Line 12:
=={{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,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,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,222:
Msgbox, You entered "%String%" and "%Int%"
ExitApp
Return</
=={{header|BaCon}}==
Requires BaCon version 4.0.1 or higher, using GTK3.
<
PRAGMA GUI gtk3
Line 1,250:
CALL GUIGET(gui, "spin", "value", &data)
PRINT data FORMAT "Entered: %g\n"</
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<
INSTALL @lib$+"WINLIB5"
ES_NUMBER = 8192
Line 1,278:
PRINT "String = """ $$buffer% """"
PRINT "Number = " ; number%
ENDPROC</
=={{header|C}}==
{{libheader|GTK}}
<
void ok_hit(GtkButton *o, GtkWidget **w)
Line 1,355:
return 0;
}</
=={{header|C++}}==
Line 1,362:
task.h
</pre>
<
#define TASK_H
Line 1,386:
} ;
#endif</
<pre>
task.cpp
</pre>
<
#include <QLabel>
#include <QHBoxLayout>
Line 1,417:
entryLayout->addLayout( lowerpart ) ;
setLayout( entryLayout ) ;
}</
<pre>
main.cpp
</pre>
<
#include "task.h"
Line 1,429:
theWidget.show( ) ;
return app.exec( ) ;
}</
=={{header|Clojure}}==
Line 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,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,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,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,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,591:
}
}
</syntaxhighlight>
=={{header|Delphi}}==
<
{$APPTYPE CONSOLE}
Line 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,666:
TextBox1_Change
End</
'''[http://cogier.com/gambas/User_input-Graphical.png Click here for a picture of the running program]'''
Line 1,672:
=={{header|Go}}==
{{libheader|gotk3}}
<
import (
Line 1,768:
window.ShowAll()
gtk.Main()
}</
=={{header|Groovy}}==
Line 1,775:
Solution:
<
def number = JOptionPane.showInputDialog ("Enter an Integer") as Integer
Line 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,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,872:
end
link graphics</
{{libheader|Icon Programming Library}}
Line 1,879:
=={{header|J}}==
'''J 8.x'''
<
pc simpleGui;
cc IntegerLabel static;cn "Enter the integer 75000";
Line 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,941:
simpleGui_run''
</syntaxhighlight>
The program stores the values entered as the variables <code>simpleGui_text</code> and <code>simpleGui_integer</code>.
Line 1,947:
=={{header|Java}}==
{{libheader|Swing}}
<
public class GetInputSwing {
Line 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,997:
twoentrywindow()
</syntaxhighlight>
=={{header|Kotlin}}==
<
import javax.swing.JOptionPane
Line 2,008:
val number = JOptionPane.showInputDialog("Enter 75000").toInt()
} while (number != 75000)
}</
=={{header|LabVIEW}}==
Line 2,015:
=={{header|Liberty BASIC}}==
<
' Typical LB graphical input/output example.This shows how LB takes user input.
Line 2,062:
[quit]
close #w
end</
=={{header|M2000 Interpreter}}==
===Simple InputBox===
<syntaxhighlight lang="m2000 interpreter">
Module CheckIt {
Def aName$="No Name", Num$
Line 2,082:
CheckIt "Thank You"
</syntaxhighlight>
===Gui User Form and TextBoxes===
Line 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,145:
}
Checkit
</syntaxhighlight>
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<
InputString["Input a number"]; Print[str, " " , ToString@nb]</
Example usage:
<pre>
Line 2,156:
=={{header|Nanoquery}}==
<
// a function to handle the main window closing
Line 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,233:
return
</syntaxhighlight>
=={{header|NewLISP}}==
<
; url: http://rosettacode.org/wiki/User_input/Graphical
; author: oofoe 2012-02-02
Line 2,281:
; No (exit) needed -- guiserver kills program on window close.
</syntaxhighlight>
[[file:newlisp-input-gui.png]]
Line 2,288:
{{libheader|gintro}}
To input the integer, we use a Gtk SpinBox as is done in the C version.
<
import gintro/[glib, gobject, gtk, gio]
Line 2,369:
let app = newApplication(Application, "Rosetta.UserInput")
discard app.connect("activate", activate)
discard app.run()</
=={{header|Oz}}==
Line 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,411:
{System.showInfo "You entered; "#Text#", "#Number}
{Application.exit 0}
end</
=={{header|Perl}}==
<
package MyApp;
Line 2,452:
package main;
MyApp->new->MainLoop;</
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{libheader|Phix/pGUI}}
<!--<
<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>
Line 2,496:
<span style="color: #7060A8;">IupClose</span><span style="color: #0000FF;">()</span>
<span style="color: #008080;">end</span> <span style="color: #008080;">if</span>
<!--</
=={{header|PicoLisp}}==
<syntaxhighlight lang="picolisp">(and
(call 'sh "-c"
(pack
Line 2,508:
(tmp "dlg") ) )
(split (in (tmp "dlg") (line)) "^I")
(cons (pack (car @)) (format (cadr @))) )</
Output:
<pre>-> ("Hello world" . 12345)</pre>
Line 2,514:
=={{header|PowerBASIC}}==
<
result$ = INPUTBOX$("Enter a string.")
MSGBOX result$
Line 2,527:
END IF
LOOP
END FUNCTION</
=={{header|PowerShell}}==
Line 2,537:
[[File:UserInputGraphical.png]]
<
[Void][Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
Line 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,640:
{{libheader|Swing}}
<
int number = int(JOptionPane.showInputDialog ("Enter an Integer"));
Line 2,646:
String string = JOptionPane.showInputDialog ("Enter a String");
println(string);</
==={{header|Processing Python mode}}===
Line 2,652:
{{libheader|Swing}}
<
def to_int(n, default=0):
Line 2,664:
a_string = JOptionPane.showInputDialog ("Enter a String")
println(a_string)</
=={{header|PureBasic}}==
<
variable=Val(InputRequester("Some other Title","Enter a Number","75000"))</
=={{header|Python}}==
Line 2,674:
{{libheader|Tkinter}}
<
root = Tkinter.Tk()
Line 2,681:
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
string = tkSimpleDialog.askstring("String", "Enter a String")
</syntaxhighlight>
{{works with|Python|3.7}}
{{libheader|Tkinter}}
<
import tkinter.simpledialog as tks
Line 2,696:
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
Line 2,712:
\ python
swap echo cr echo$</
=={{header|R}}==
<syntaxhighlight lang="r">
library(gWidgets)
options(guiToolkit="RGtk2") ## using gWidgtsRGtk2
Line 2,736:
gmessage("You failed this simple task", parent=w)
})
</syntaxhighlight>
=={{header|Racket}}==
<syntaxhighlight lang="racket">
#lang racket
(require racket/gui)
Line 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,781:
}
$app.run;</
=={{header|Rascal}}==
<
import vis::Figure;
Line 2,797:
text(str(){return " <integer == "75000" ? "Correct" : "Wrong">";})];
render(grid([row1, row2]));
}</
Output:
Line 2,807:
[[File:Useringui_rebol.png]]
<
Title: "Graphical User Input"
URL: http://rosettacode.org/wiki/User_Input_-_graphical
Line 2,864:
show [si ni] ; Repainting multiple objects at once.
]
]</
=={{header|REXX}}==
Line 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,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,936:
num2 = number(temp2)
if num2 = 75000 label2{settext("OK")} else label2{settext("NOT OK")} ok
</syntaxhighlight>
Output:
Line 2,945:
{{libheader|Ruby/Tk}}
<
def main
Line 2,983:
end
main</
{{libheader|Shoes}}
<
string = ask('Enter a string:')
begin
Line 2,992:
end while number.to_i != 75000
para %Q{you entered the string "#{string}" and the number #{number}}
end</
=={{header|Run BASIC}}==
<
<TR><TD colspan=2>Please input a string and a number</TD></TR>
Line 3,015:
[ex]
end</
=={{header|Scala}}==
{{libheader|Scala}}
<
import scala.swing.Swing
Line 3,030:
Nil, "ham")
println(responce)
}</
=={{header|Scratch}}==
Line 3,041:
=={{header|Sidef}}==
<
var gui = %s'Gtk2::Builder'.new;
Line 3,222:
</child>
</object>
</interface></
=={{header|Standard ML}}==
Works with PolyML
<
open Motif ;
Line 3,249:
end ;
inputWindow () ;</
enter text, press enter, delete, enter 75000, press enter, result:
!store ;
Line 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,276:
This program leaves the requested values in the global variables ''s'' and ''n''.
<
Dialog
Title "Rosetta Code"
Line 3,283:
EndDlog
74999 + n → n
EndPrgm</
=={{header|VBScript}}==
{{works with|Windows Script Host}}
<
Wscript.Echo strUserIn</
=={{header|Vedit macro language}}==
Line 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,310:
In the case of the number, it keeps requesting input until 75000 is entered and then quits.
<
import "input" for Keyboard, Clipboard
import "dome" for Window, Process
Line 3,377:
}
var Game = Main.new()</
{{out}}
|