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!

global varible 1

Status
Not open for further replies.

stewang

Programmer
Aug 21, 2003
77
0
0
NZ
Hello all:
In my application, I'd like to go to my desire directory when I click on different menu item, For example, If I click on the favorite of the menu item, I will go to "/home/stewang/Favourite ", for type of music will go to the path of the "/home/stewang/TypeOfmusic".

But my program does nothing, it always go the path where I
use my application.

Could anyone help me, please.

Thanks
rgds
stewang


Code:
menu .mbar
. configure -menu .mbar
menu .mbar.load -tearoff 0


# Add them to the menubar, providing "Alt-style" keyboard
# accelerators simply by indication which character in
# the label to underline.

.mbar add cascade -label "Load" -underline 0     -menu .mbar.load

set ::dir " "

.mbar.load add command -label "Favourite..." -underline 0     -command { set ::dir "/home/stewang/Favourite" } -command openFile
.mbar.load add command -label "TypeOfMusic..." -underline 0     -command { set ::dir "/home/stewang/TypeOfmusic" } -command openFile
.mbar.load add command -label "AgeOfItem..." -underline 0     -command { set ::dir "/home/stewang/AgeOfItem" } -command openFile

proc openFile { } {
  set filename [tk_getOpenFile -defaultextension tk -initialdir $::dir ]
}
 
I think you really don't need a global variable here (unless there's something else going on elsewhere in the script). I would give the proc, openFile an argument, dir:
proc openFile {dir} {
set filename [tk_getOpenFile ... intialdir $dir]
}

But, if you want to keep "dir" global, I think your problem is the 2 -command options. Try:
.... -command {set ::dir "whatever"; openFile}

Bob Rashkin
rrashkin@csc.com
 
Thanks Bong, I think I prefer the first one.

rgds
stewang
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top