Hell all:
In my application, I'd like my menu items of "open" and "save" from the menu of file to have lightgrey colour, but after a new window pop up which from the menu item of "newwindow" under the menu of "window", then they will change to dark colour.
And also if anyone click on the menu items of "open" and "save" before pop up a window, it will pop up a dialog box
with some message which say " you need to pop up a window before you use this"
I tried to use -bg lightgrey for colour, but it doesn't work.
and I also tried some code for pop up a dialog box,like,
if {.t == NULL && .mbar.file != NULL }
{
tk_messageBox -massage "hello"
}
But all of them do nothing.
Could anyone help me, please.
Thanks
rgds
stewang
In my application, I'd like my menu items of "open" and "save" from the menu of file to have lightgrey colour, but after a new window pop up which from the menu item of "newwindow" under the menu of "window", then they will change to dark colour.
And also if anyone click on the menu items of "open" and "save" before pop up a window, it will pop up a dialog box
with some message which say " you need to pop up a window before you use this"
I tried to use -bg lightgrey for colour, but it doesn't work.
and I also tried some code for pop up a dialog box,like,
if {.t == NULL && .mbar.file != NULL }
{
tk_messageBox -massage "hello"
}
But all of them do nothing.
Could anyone help me, please.
Thanks
rgds
stewang
Code:
package require Tk
# the menu bar
menu .mbar
. configure -menu .mbar
menu .mbar.file -tearoff 0
.mbar add cascade -label "File" -underline 0 -menu .mbar.file
.mbar.file add command -label "Open" -underline 0 -command openFile
.mbar.file add command -label "Save" -underline 0 -command saveFile
.mbar.file add separator
menu .mbar.window -tearoff 0
.mbar add cascade -label "Window" -underline 0 -menu .mbar.window
.mbar.window add command -label "NewWindow" -underline 0 -command { toplevel .t }
# the list box
set ::names {}
listbox .l -listvar ::names -width 40
pack .l -expand 1 -fill both
# the actions
# get some file names
# add the new ones to the listbox
# do something with the content of each new file
array set ::pathes {}
proc openFile {} {
# get some file names
# set filenames [tk_getOpenFile -multiple 1];
foreach filenames [tk_getOpenFile -multiple 1 ] {
foreach fn $filenames {
# get simple name
set name [file tail $fn]
# check if its a new one
if {![info exists ::pathes($name)]} {
# add the name to the array
puts "set ::pathes($name) $fn"
set ::pathes($name) $fn
# add the name to the listbox
lappend ::names $name
# get the file content and do something with it
set thefile [open $fn r]
#puts "the file : $thefile"
set filecontent [read $thefile]
close $thefile
}
}
# sort the listbox content
set ::names [lsort $::names]
}
}
# get the currently selected name
# copy the corresponding file somewhere
# remove the name from the listbox
proc saveFile {} {
# get the currently selected name
set n [.l curselection]
if {$n != ""} {
# get the old name
set source [lindex $::names $n]
# get the new name
set target [tk_getSaveFile]
if {$target != ""} {
# copy the file content to the new position
file copy $::pathes($source) $target
}
}
}