只需加快tk/ruby即可。如何選擇tk輸入框中的所有文本(紅寶石)
我有一個非常簡單的窗口,一行文本輸入區,一個「去」按鈕和一個反饋標籤。
想要的行爲是用戶輸入一些文本,點擊「去」按鈕,代碼做了一些工作。
當它的全部輸入框應該有輸入的文本,但它應該被突出顯示,並在輸入框中的焦點,以便如果用戶開始再次打字框中將被覆蓋。
在.net中這很容易,只需說.selectall輸入字段。無法弄清楚如何在tk中做到這一點。
root = TkRoot.new {title "Test App"}
content = Tk::Tile::Frame.new(root) {padding "3 3 12 12"}.grid(:sticky => 'nsew')
TkGrid.columnconfigure root, 0, :weight => 1; TkGrid.rowconfigure root, 0, :weight => 1
$job= TkVariable.new; $status = TkVariable.new
$j = Tk::Tile::Entry.new(content) {
width 14; textvariable $job}.grid(:column => 1, :row => 1, :sticky => 'we')
Tk::Tile::Button.new(content) {
text 'Find Job'
command {go_do_something}
}.grid(:column => 2, :row => 1, :sticky => 'w')
def go_do_something
# ... do some processing, then I want to...
# $j.focus
# $j.select_all
end
在此先感謝
我不得不使用winapi將焦點放回窗口,然後做一個$ j.focus; $ j.selection_range(0,100)。有沒有更簡單的方法讓焦點返回到應用程序,然後經歷一堆windows API調用? –