Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Add a cancel button to my click me/click window.

Status
Not open for further replies.

WTHolmes

Technical User
Mar 22, 2007
18
0
0
US
Howdy,

It's me again. I would like to add a cancel button to the right of the click me/clicked button that Bong created. This cancel button will close the tp1 window, leaving just the main window open. I have included code below to make it easier.

I want to thank you in advance, with your help, I am learning Tcl/Tk. (A special thank you to Bong!)

Thanks again,

WTHolmes

proc menu_clicked { no opt } {
tk_messageBox -message \
"You have clicked $opt.\nThis function is not implanted yet."
}

#Declare that there is a menu
menu .mbar
. config -menu .mbar

#The Main Buttons
.mbar add cascade -label "Menu1" -underline 4 \
-menu [menu .mbar.file -tearoff 0]
.mbar add cascade -label "Menu2" \
-underline 4 -menu [menu .mbar.oth -tearoff 1]
.mbar add cascade -label "Menu3" -underline 4 \
-menu [menu .mbar.help -tearoff 0]

## Menu1 Menu ##
set m .mbar.file
$m add command -label "M1-L1-1" -underline 6 \
-command { .txt delete 1.0 end } ;# A new item called New is added.
$m add checkbutton -label "M1-L1-2" -underline 6 -command { menu_clicked 1 "M1-L2-2" }
$m add command -label "M1-L1-3" -underline 6 -command { menu_clicked 1 "M1-L2-3" }
$m add separator
$m add command -label "Quit" -underline 0 \
-command {set answer [tk_messageBox -message "Really Quit?" -type yesno -icon question]
switch -- $answer {
yes exit
no {tk_messageBox -message "I know you can't resist me!" -type ok}
}
}

## Menu2 Menu ##
set m .mbar.oth
$m add cascade -label "M2-L1-1" -underline 0 -menu [menu $m.mnu -title "M2-L1-1"]
$m.mnu add command -label "M2-L2-1" -underline 6 \
-command { .txt insert end "You have chosen M2-L2-1\n"}
$m.mnu add command -label "M2-L2-2" -underline 6 -command { \
.txt insert end "You have chosen M2-L2-2\n"}
$m.mnu add command -label "M2-L2-3" -underline 6 \
-command { .txt insert end "You have chosen M2-L2-3\n"}
$m add command -label "All" -underline 0 \
-command { .txt insert end {You have chosen All}
}

## Menu3 ##
set m .mbar.help
$m add command -label "M3-L1-1" -underline 0 -command {
.txt delete 1.0 end
.txt insert end {
You have chosen M3-L1-1}
}
proc push_button {} {
toplevel .tp1
pack [label .tp1.lb1 -text "your text here"] -side top
pack [button .tp1.b1 -text "Click Me" -command {.tp1.b1 configure -text Clicked; bttn2}]
}
toplevel .tp2
pack [button .tp2.b2 -text "Cancel" -command {.tp2.b2 configure -text Cancel; bttn3}]
proc bttn2 {} {
update
after 10000
.tp1.b1 configure -text "Click Me Again"
}

button .but -text "Push Me" -command "push_button"
pack .but


#Making a text area
text .txt -width 55
pack .txt
 
Code:
toplevel .tp1 
    pack [label .tp1.lb1 -text "your text here"] -side top
    pack [button .tp1.b1 -text "Click Me" -command {.tp1.b1 configure -text Clicked; bttn2}][red] -side left
pack [button .tp1.cncl -text Cancel -command {destroy .tp1}] -side left[/red]
}

_________________
Bob Rashkin
 
Thanks again Bong, you did it again, You Da Man!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top