TCL/TK User Input Window

2.1k views Asked by At

I'm looking for a predefined tk window like tk_messageBox where a user can input a string in a white line. I couldn't find one in the Tcl / Tk man page (https://www.tcl.tk/man/tcl/TkCmd/contents.htm)...

1

There are 1 answers

0
Donal Fellows On

There's no predefined popup text-entry window. You'll need to make one yourself with a toplevel, an entry and (probably) at least one button. Maybe a label too.

Here's the simplest thing that could work at all:

set foo "This is some text."

toplevel .t
pack [entry .t.e -variable foo]
pack [button .t.b -text "OK" -command {destroy .t}]
bind .t <Return> {.t.b invoke}
focus .t.e

tkwait window .t

puts "The variable contains '$foo'"

You will probably need to customise it further…