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">
<lang AArch64 Assembly>
/* ARM assembly AARCH64 Raspberry PI 3B */
/* program inputWin64.s */
Line 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,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 1,222:
Msgbox, You entered "%String%" and "%Int%"
ExitApp
Return</langsyntaxhighlight>
 
=={{header|BaCon}}==
Requires BaCon version 4.0.1 or higher, using GTK3.
<langsyntaxhighlight lang="bacon">OPTION GUI TRUE
PRAGMA GUI gtk3
 
Line 1,250:
 
CALL GUIGET(gui, "spin", "value", &data)
PRINT data FORMAT "Entered: %g\n"</langsyntaxhighlight>
 
=={{header|BBC BASIC}}==
{{works with|BBC BASIC for Windows}}
<langsyntaxhighlight lang="bbcbasic"> INSTALL @lib$+"WINLIB2"
INSTALL @lib$+"WINLIB5"
ES_NUMBER = 8192
Line 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,355:
 
return 0;
}</langsyntaxhighlight>
 
=={{header|C++}}==
Line 1,362:
task.h
</pre>
<langsyntaxhighlight lang="cpp">#ifndef TASK_H
#define TASK_H
 
Line 1,386:
} ;
 
#endif</langsyntaxhighlight>
<pre>
task.cpp
</pre>
<langsyntaxhighlight lang="cpp">#include <QLineEdit>
#include <QLabel>
#include <QHBoxLayout>
Line 1,417:
entryLayout->addLayout( lowerpart ) ;
setLayout( entryLayout ) ;
}</langsyntaxhighlight>
<pre>
main.cpp
</pre>
<langsyntaxhighlight lang="cpp">#include <QApplication>
#include "task.h"
 
Line 1,429:
theWidget.show( ) ;
return app.exec( ) ;
}</langsyntaxhighlight>
 
=={{header|Clojure}}==
Line 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,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,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,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,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,591:
}
}
</syntaxhighlight>
</lang>
 
=={{header|Delphi}}==
<langsyntaxhighlight Delphilang="delphi">program UserInputGraphical;
 
{$APPTYPE CONSOLE}
Line 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,666:
TextBox1_Change
End</langsyntaxhighlight>
 
'''[http://cogier.com/gambas/User_input-Graphical.png Click here for a picture of the running program]'''
Line 1,672:
=={{header|Go}}==
{{libheader|gotk3}}
<langsyntaxhighlight lang="go">package main
 
import (
Line 1,768:
window.ShowAll()
gtk.Main()
}</langsyntaxhighlight>
 
=={{header|Groovy}}==
Line 1,775:
 
Solution:
<langsyntaxhighlight lang="groovy">import javax.swing.JOptionPane
 
def number = JOptionPane.showInputDialog ("Enter an Integer") as Integer
Line 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,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,872:
end
 
link graphics</langsyntaxhighlight>
 
{{libheader|Icon Programming Library}}
Line 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,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,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,947:
=={{header|Java}}==
{{libheader|Swing}}
<langsyntaxhighlight lang="java">import javax.swing.*;
 
public class GetInputSwing {
Line 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,997:
 
twoentrywindow()
</syntaxhighlight>
</lang>
 
=={{header|Kotlin}}==
<langsyntaxhighlight lang="scala">// version 1.1
 
import javax.swing.JOptionPane
Line 2,008:
val number = JOptionPane.showInputDialog("Enter 75000").toInt()
} while (number != 75000)
}</langsyntaxhighlight>
 
=={{header|LabVIEW}}==
Line 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,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,082:
CheckIt "Thank You"
 
</syntaxhighlight>
</lang>
 
===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">
<lang M2000 Interpreter>
Module Checkit {
Declare Form1 Form
Line 2,145:
}
Checkit
</syntaxhighlight>
</lang>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<langsyntaxhighlight Mathematicalang="mathematica">str = InputString["Input a string"]; nb =
InputString["Input a number"]; Print[str, " " , ToString@nb]</langsyntaxhighlight>
Example usage:
<pre>
Line 2,156:
 
=={{header|Nanoquery}}==
<langsyntaxhighlight Nanoquerylang="nanoquery">import Nanoquery.Util.Windows
 
// a function to handle the main window closing
Line 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,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,281:
 
; No (exit) needed -- guiserver kills program on window close.
</syntaxhighlight>
</lang>
 
[[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.
<langsyntaxhighlight Nimlang="nim">import strutils
import gintro/[glib, gobject, gtk, gio]
 
Line 2,369:
let app = newApplication(Application, "Rosetta.UserInput")
discard app.connect("activate", activate)
discard app.run()</langsyntaxhighlight>
 
=={{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".
<langsyntaxhighlight lang="oz">functor
import
Application
Line 2,411:
{System.showInfo "You entered; "#Text#", "#Number}
{Application.exit 0}
end</langsyntaxhighlight>
 
=={{header|Perl}}==
<langsyntaxhighlight lang="perl">use Wx;
 
package MyApp;
Line 2,452:
package main;
 
MyApp->new->MainLoop;</langsyntaxhighlight>
 
=={{header|Phix}}==
{{libheader|Phix/basics}}
{{libheader|Phix/pGUI}}
<!--<langsyntaxhighlight Phixlang="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>
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>
<!--</langsyntaxhighlight>-->
 
=={{header|PicoLisp}}==
<syntaxhighlight lang="picolisp">(and
<lang PicoLisp>(and
(call 'sh "-c"
(pack
Line 2,508:
(tmp "dlg") ) )
(split (in (tmp "dlg") (line)) "^I")
(cons (pack (car @)) (format (cadr @))) )</langsyntaxhighlight>
Output:
<pre>-> ("Hello world" . 12345)</pre>
Line 2,514:
=={{header|PowerBASIC}}==
 
<langsyntaxhighlight lang="powerbasic">FUNCTION PBMAIN () AS LONG
result$ = INPUTBOX$("Enter a string.")
MSGBOX result$
Line 2,527:
END IF
LOOP
END FUNCTION</langsyntaxhighlight>
 
=={{header|PowerShell}}==
Line 2,537:
[[File:UserInputGraphical.png]]
 
<langsyntaxhighlight PowerShelllang="powershell">#region Define the Windows Form
[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 }</langsyntaxhighlight>
 
=={{header|Processing}}==
Line 2,640:
{{libheader|Swing}}
 
<langsyntaxhighlight lang="java">import javax.swing.JOptionPane;
 
int number = int(JOptionPane.showInputDialog ("Enter an Integer"));
Line 2,646:
String string = JOptionPane.showInputDialog ("Enter a String");
println(string);</langsyntaxhighlight>
 
==={{header|Processing Python mode}}===
Line 2,652:
{{libheader|Swing}}
 
<langsyntaxhighlight Pythonlang="python">from javax.swing import JOptionPane
 
def to_int(n, default=0):
Line 2,664:
 
a_string = JOptionPane.showInputDialog ("Enter a String")
println(a_string)</langsyntaxhighlight>
 
=={{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,674:
 
{{libheader|Tkinter}}
<langsyntaxhighlight lang="python">import Tkinter,tkSimpleDialog
 
root = Tkinter.Tk()
Line 2,681:
number = tkSimpleDialog.askinteger("Integer", "Enter a Number")
string = tkSimpleDialog.askstring("String", "Enter a String")
</syntaxhighlight>
</lang>
 
{{works with|Python|3.7}}
 
{{libheader|Tkinter}}
<langsyntaxhighlight lang="python">import tkinter
import tkinter.simpledialog as tks
Line 2,696:
 
tkinter.messagebox.showinfo("Results", f"Your input:\n {number} {string}")
</syntaxhighlight>
</lang>
 
=={{header|Quackery}}==
{{trans|Python}}
<syntaxhighlight lang="quackery">$ \
<lang Quackery>$ \
import tkinter
import tkinter.simpledialog as tks
Line 2,712:
\ python
swap echo cr echo$</langsyntaxhighlight>
 
=={{header|R}}==
<syntaxhighlight lang="r">
<lang R>
library(gWidgets)
options(guiToolkit="RGtk2") ## using gWidgtsRGtk2
Line 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,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,781:
}
 
$app.run;</langsyntaxhighlight>
 
=={{header|Rascal}}==
<langsyntaxhighlight lang="rascal">import vis::Render;
import vis::Figure;
 
Line 2,797:
text(str(){return " <integer == "75000" ? "Correct" : "Wrong">";})];
render(grid([row1, row2]));
}</langsyntaxhighlight>
 
Output:
Line 2,807:
[[File:Useringui_rebol.png]]
 
<langsyntaxhighlight REBOLlang="rebol">REBOL [
Title: "Graphical User Input"
URL: http://rosettacode.org/wiki/User_Input_-_graphical
Line 2,864:
show [si ni] ; Repainting multiple objects at once.
]
]</langsyntaxhighlight>
 
=={{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.
<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,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,936:
num2 = number(temp2)
if num2 = 75000 label2{settext("OK")} else label2{settext("NOT OK")} ok
</syntaxhighlight>
</lang>
Output:
 
Line 2,945:
 
{{libheader|Ruby/Tk}}
<langsyntaxhighlight lang="ruby">require 'tk'
 
def main
Line 2,983:
end
 
main</langsyntaxhighlight>
 
{{libheader|Shoes}}
<langsyntaxhighlight lang="ruby">Shoes.app do
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</langsyntaxhighlight>
 
=={{header|Run BASIC}}==
<langsyntaxhighlight lang="runbasic">html "<TABLE BORDER=1 BGCOLOR=silver>
<TR><TD colspan=2>Please input a string and a number</TD></TR>
 
Line 3,015:
 
[ex]
end</langsyntaxhighlight>
 
=={{header|Scala}}==
{{libheader|Scala}}
<langsyntaxhighlight lang="scala">import swing.Dialog.{Message, showInput}
import scala.swing.Swing
Line 3,030:
Nil, "ham")
println(responce)
}</langsyntaxhighlight>
 
=={{header|Scratch}}==
Line 3,041:
 
=={{header|Sidef}}==
<langsyntaxhighlight lang="ruby">var gtk2 = require('Gtk2') -> init;
 
var gui = %s'Gtk2::Builder'.new;
Line 3,222:
</child>
</object>
</interface></langsyntaxhighlight>
 
=={{header|Standard ML}}==
Works with PolyML
<langsyntaxhighlight Standardlang="standard MLml">open XWindows ;
open Motif ;
 
Line 3,249:
end ;
 
inputWindow () ;</langsyntaxhighlight>
enter text, press enter, delete, enter 75000, press enter, result:
!store ;
Line 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,276:
This program leaves the requested values in the global variables ''s'' and ''n''.
 
<langsyntaxhighlight lang="ti89b">Prgm
Dialog
Title "Rosetta Code"
Line 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,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,310:
 
In the case of the number, it keeps requesting input until 75000 is entered and then quits.
<langsyntaxhighlight ecmascriptlang="wren">import "graphics" for Canvas, Color
import "input" for Keyboard, Clipboard
import "dome" for Window, Process
Line 3,377:
}
 
var Game = Main.new()</langsyntaxhighlight>
 
{{out}}
9,482

edits