Monday 13 March 2017

GUI_ Menu bar, Menus and Menu Items.

#!/bin/sh
# simpel_mny.tcl \
exec tclsh "$0" ${1+"$@"}
proc menu_clicked { no opt } {
tk_messageBox -message "you have clicked $opt. \n This function is not implanted yet "
}
#Declare that there is a menu

menu .mbar
. config -menu .mbar
#the main buttons
# cascade, checkbutton, command, radiobutoon, or separator,

.mbar add cascade -label "File" -underline 0 \
-menu [menu .mbar.file -tearoff 0]
.mbar add cascade -label "Others" \
-underline 0 -menu [menu .mbar.oth -tearoff 1]
.mbar add cascade -label "Help" -underline 0 -menu [menu .mbar.help -tearoff 0]

##File Menu##
set m .mbar.file
$m add command -label "New" -underline 0 \
-command { .txt delete 1.0 end} ; #A new item called New is added
$m add checkbutton -label "Open" -underline 0 -command {menu_clicked 1 "Open"}
$m add command -label "Save" -underline 0 -command {menu_clicked 1 "Save"}
$m add separator
$m add command -label "Exit" -underline 1 -command exit

##other Menu ##
set m .mbar.oth
$m add cascade -label "Insert" -underline 0 -menu [menu $m.mnu -title "Insert"]

$m.mnu add command -label "Name" -command {.txt insert end "Name : Gurinder V A\n"}
$m.mnu add command -label "Website" \
-command {.txt insert end "Website: https://www.blogger.com/\n"}
$m.mnu add command -label "Email" \
-command {.txt insert end "Email : gurinderpalsingh900@gmail.com\n"}

$m add command -label "Insert All"  -underline 7 \
-command {.txt insert end {Name : Gurinder V A
Website: https://www.blogger.com/
Email : gurinderpalsingh900@gmail.com}
}  
#help
set m .mbar.help
$m add command -label "About" -command {
.txt delete 1.0 end
.txt insert end {
About
---------
this script created to make a menu for a tcl/tk class
made by Gurinder pal Singh
segveris.blogspot.in
}
}
#making a text area
text .txt -width 50
pack .txt

1 comment:

  1. menubutton buttonName ?options?

    -text displayText The text to display on this button.
    -textvariable varName The variable that contains the text to be
    displayed.
    -underline charPosition Selects a position for a hot key.
    -menu menuName The name of the menu widget associated with
    this menubutton.

    -tearoff boolean Allows (or disallows) a menu to be removed from the menubutton and displayed in a permanent window. This is enabled by default.

    ReplyDelete