GUI component interaction: Difference between revisions

(→‎{{header|Julia}}: marked incorrect)
Line 1,884:
 
=={{header|Julia}}==
<lang julia>#=
{{incorrect|Julia|fails with syntax: { } vector syntax is discontinued (line 4) on 1.4}}
## The task: For a minimal "application", write a program that
<lang julia>
## presents a form with three components to the user: A numeric input
## field ("Value") and two buttons ("increment" and "random").
=#
 
using Tk
 
w = Toplevel("Component Interaction Example")
fr = Frame(w)
pack(fr, {:expand=>true, :fill => "both"})
## The task: For a minimal "application", write a program that
## presents a form with three components to the user: A numeric input
## field ("Value") and two buttons ("increment" and "random").
 
value = Entry(fr, "")
Line 1,904 ⟶ 1,906:
set_value(value, "0") ## The field is initialized to zero.
 
incrementvalue(s) = (val = parse(Int, get_value(value)); set_value(value, string(val + 1)))
tk_bind(increment, "command") do path ## increment its value with the "increment" button.
bind(increment, "command", incrementvalue)
val = get_value(value) | float
set_value(value, string(val + 1))
end
 
 
function validate_command(path, P)
try
if length(P) > 0 parsefloat&& parse(Float64, P) end
tcl("expr", "TRUE")
catch e
Line 1,922 ⟶ 1,921:
tcl(W, "delete", "@0", "end")
end
tk_configure(value, {:validate=>"key", :validatecommand=>validate_command, :invalidcommand=>invalid_command })
 
"""
## Pressing the "random" button presents a confirmation dialog, and resets the field's value to a random value if the answer is "Yes".
Pressing the "random" button presents a confirmation dialog and
tk_bind(random, "command") do path
## Pressing the "random" button presents a confirmation dialog, and resets the field's value to a random value if the answer is "Yes".
out = Messagebox(w, "Randomize input", "Select a new random number?")
"""
if out == "ok"
function randval(s)
new_value = floor(100*rand(1))[1]
out = Messagebox(w, title="Randomize input", detail="Select a new random number?")
set_value(value, string(new_value))
if out == "ok"
end
new_value = floor(100*rand(collect(1:99))[1]
set_value(value, string(val + 1new_value))
end
end
tk_bindbind(random, "command"), do pathrandval)
 
while true sleep(1); end
</lang>
 
4,105

edits