不過新來這和我創建了一個有趣的問題我自己,我解決不了......想要創建一個可編輯的彈出框
我試圖設計我自己的「彈出「框允許用戶編輯現有的字符串。當按下按鈕時彈出,在輸入框中顯示字符串。一旦用戶編輯了字符串(或不),他點擊「確定」按鈕,它就會消失,腳本現在應該有新的字符串。
我的做法是這樣的:
按下按鈕,創建一個頂層窗口有三個部件:
- 簡單的標籤「編輯字符串,按確定完成時」;
- 包含預定義字符串的可編輯條目;
- 按下「OK」按鈕時會破壞頂層窗口。
我有種工作,但無法弄清楚如何獲得編輯的字符串。
我意識到我的根本問題是我沒有考慮「事件驅動」條款。看起來這應該很容易實現,但是在這一點上我看不到森林。
我錯過了什麼?我是否過分複雜呢?
#!/usr/bin/wish
# Create the Pop-up box
proc popUpEntry { labelString } {
global myString
puts "POP:myString = $myString"
set top [toplevel .top]
set labelPop [label $top.labelPop -text $labelString ]
set entryPop [entry $top.entryPop -bg white -width 20 -textvar $myString ]
set buttonPop [button $top.buttonPop -text "Ok" -command { destroy .top } ]
pack $labelPop
pack $entryPop
pack $buttonPop
}
# Pop-up command
proc DoPop {} {
global myString
set popUpLabel "Edit string, press ok when done:"
puts "Before: myString = $myString"
popUpEntry $popUpLabel
puts "After: myString = $myString"
}
# Initalize
set myString "String at start"
# Pop-up button invokes the pop-up command
set buttonPop [button .buttonPop -width 10 -text "Pop" -command {DoPop} ]
pack $buttonPop
#
啊。事實如此明顯。謝謝! – user1074069 2012-08-03 14:42:10