On Wednesday, August 8, 2018 at 10:04:08 PM UTC-7, Ashok wrote:
> Bind to <Unmap> to withdraw the window.
>
> Something along the lines of (cut'n'pasted from a working app but not
> tested separately)
>
> bind $::mainWin <Unmap> "+minimize %W"
>
> proc minimize {win args} {
> if {$win ne $::mainWin} return
>
> # A second binding can fire when we withdraw below so ignore that
> # else might fire the event continuously
> if {[wm state $win] eq "withdrawn"} return
>
> wm withdraw $::mainWin
> }
>
> I'm only a dabbler in Tk so there might be a better way.
>
> /Ashok
>
Thanks, that worked for me.
The only thing left is how to remove the windows tray icon on exit. Right now, it stays until I hover over it with the mouse, then it goes away.
The code I'm using comes from the wiki, as follows:
package require twapi_resource
package require twapi_shell
package require twapi_ui
# Create with X
set ID [twapi::systemtray addicon [twapi::load_icon_from_system hand] cb]
# Change to Triangle NAME must be one of sample, hand, ques, bang, note, winlogo, warning, error, information or shield.
twapi::systemtray modifyicon $ID -hicon [twapi::load_icon_from_system bang]
# Set tooltip help
twapi::systemtray modifyicon $ID -tip "New Tooltip"
proc cb {ID Message lPos TimeStamp} {
lassign $lPos xPos yPos
switch $Message {
select - keyselect {
# click action here
}
contextmenu {
if {![winfo exists .guiWinicoPopup]} {
menu .guiWinicoPopup -tearoff 0
.guiWinicoPopup add command -label "exit" -command {exit}
.guiWinicoPopup add command -label "restore" -command {wm deiconify .}
}
set hWinNotify [::twapi::Twapi_GetNotificationWindow]
::twapi::set_foreground_window $hWinNotify
.guiWinicoPopup post $xPos $yPos
.guiWinicoPopup activate 0
::twapi::PostMessage $hWinNotify 0 0 0
}
}
}