GUI component interaction: Difference between revisions
Content deleted Content added
→{{header|Julia}}: marked incorrect |
|||
Line 1,884:
=={{header|Julia}}==
<lang julia>#=▼
▲<lang julia>
=#
using Tk
w = Toplevel("Component Interaction Example")
fr = Frame(w)
pack(fr,
▲## 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)))
bind(increment, "command", incrementvalue)
set_value(value, string(val + 1))▼
end▼
function validate_command(path, P)
try
tcl("expr", "TRUE")
catch e
Line 1,922 ⟶ 1,921:
tcl(W, "delete", "@0", "end")
end
"""
## 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▼
▲
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?")
▲ if out == "ok"
▲ end
end
while true sleep(1); end
</lang>
|