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!

change colour of menu item and a dialog box for menu iem

Status
Not open for further replies.

stewang

Programmer
Aug 21, 2003
77
0
0
NZ
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

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
       
      }
    }
  }
 
Hello all:
Thanks for you come to my question, I decide to give up this problem, I think it is not very good idea for my application.

Thanks
rgds
stewang
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top