GUI component interaction: Difference between revisions
Content added Content deleted
(→{{header|Julia}}: marked incorrect) |
|||
Line 1,884: | Line 1,884: | ||
=={{header|Julia}}== |
=={{header|Julia}}== |
||
⚫ | |||
{{incorrect|Julia|fails with syntax: { } vector syntax is discontinued (line 4) on 1.4}} |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
=# |
|||
using Tk |
using Tk |
||
w = Toplevel("Component Interaction Example") |
w = Toplevel("Component Interaction Example") |
||
fr = Frame(w) |
fr = Frame(w) |
||
pack(fr, |
pack(fr, expand=true, fill="both") |
||
⚫ | |||
⚫ | |||
⚫ | |||
value = Entry(fr, "") |
value = Entry(fr, "") |
||
Line 1,904: | Line 1,906: | ||
set_value(value, "0") ## The field is initialized to zero. |
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 |
|||
⚫ | |||
⚫ | |||
function validate_command(path, P) |
function validate_command(path, P) |
||
try |
try |
||
length(P) > 0 && parse(Float64, P) |
|||
tcl("expr", "TRUE") |
tcl("expr", "TRUE") |
||
catch e |
catch e |
||
Line 1,922: | Line 1,921: | ||
tcl(W, "delete", "@0", "end") |
tcl(W, "delete", "@0", "end") |
||
end |
end |
||
tk_configure(value, {:validate=>"key", :validatecommand=>validate_command, :invalidcommand=>invalid_command }) |
|||
""" |
|||
⚫ | |||
Pressing the "random" button presents a confirmation dialog and |
|||
⚫ | |||
⚫ | |||
⚫ | |||
""" |
|||
⚫ | |||
function randval(s) |
|||
⚫ | |||
⚫ | |||
set_value(value, string(new_value)) |
|||
⚫ | |||
end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
end |
end |
||
⚫ | |||
while true sleep(1); end |
|||
</lang> |
</lang> |
||