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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

TK (solaris) Create a message popup with clear close button

Status
Not open for further replies.

alfie002

Technical User
Mar 3, 2004
121
GB
Hello all,

I know very little about TK (running on Solaris). I have a need to create a popup screen, which will be called by a shell script, to display a message. The popup should have a close button as well.

Any help would be greatly appreciated.

Thanks

Alf
 
I think you want the Tk "message box":
NAME
tk_messageBox - pops up a message window and waits for user response.

SYNOPSIS
tk_messageBox ?option value ...?


DESCRIPTION
This procedure creates and displays a message window with an application-specified message, an icon and a set of buttons. Each of the buttons in the message window is identified by a unique symbolic name (see the -type options). After the message window is popped up, tk_messageBox waits for the user to select one of the buttons. Then it returns the symbolic name of the selected button. The following option-value pairs are supported:

-default name
Name gives the symbolic name of the default button for this message window ('ok', 'cancel', and so on). See -type for a list of the symbolic names. If this option is not specified, the first button in the dialog will be made the default.
-icon iconImage
Specifies an icon to display. IconImage must be one of the following: error, info, question or warning. If this option is not specified, then the info icon will be displayed.
-message string
Specifies the message to display in this message box.
-parent window
Makes window the logical parent of the message box. The message box is displayed on top of its parent window.
-title titleString
Specifies a string to display as the title of the message box. The default value is an empty string.
-type predefinedType
Arranges for a predefined set of buttons to be displayed. The following values are possible for predefinedType:
abortretryignore
Displays three buttons whose symbolic names are abort, retry and ignore.
ok
Displays one button whose symbolic name is ok.
okcancel
Displays two buttons whose symbolic names are ok and cancel.
retrycancel
Displays two buttons whose symbolic names are retry and cancel.
yesno
Displays two buttons whose symbolic names are yes and no.
yesnocancel
Displays three buttons whose symbolic names are yes, no and cancel.
EXAMPLE
set answer [tk_messageBox -message "Really quit?" -type yesno -icon question]
switch -- $answer {
yes exit
no {tk_messageBox -message "I know you like this application!" -type ok}
}

_________________
Bob Rashkin
 
hello bong,

many thanks for the reply. Looks as though this will do the trikc. Bong, once I have created the tk file with my configuration, how do I launch the popup ?

Thanks

Alf
 
As in the example, the statement:
tk_messageBox -message <[red]your message string[/red]> -type <[red]your type choice[/red]> -icon <[red]your icon[/red]>
will pop up the message box. So the condition that causes you to want to launch the pop up should trigger such a statement. As in the example, you should capture the return just for good form.

_________________
Bob Rashkin
 
Hello Bong,

what binary do I use to execute the tk script. I am assuming the tk_message -message < > -type < > -icon < > are the command line parameters to pass to the executable.

Apologies, but I don't really know much about tcl/tk.

Thanks

Alf
 
I'm not sure what the Solaris executable is named but it's probably something like wishxx, where "xx" is the version.

_________________
Bob Rashkin
 
hello bong,

still having a problem.

I am using the following

./wish8.3 -default ok -icon warning -message "test" -title "NATS" -type ok

where ./wich8.3 is the binary.

Is my syntax wrong ?

Thanks

Alf
 
I don't know. Is the "wish" executable in your current directory? Try typing "wish8.3" and see what happens. You should get a console and a top level window.

_________________
Bob Rashkin
 
hello bong,

yes, I am running the command from the wish8.3 directory and yes you are right, a x console does appear when I run the binary. When I run the binary with the script file I get the following error message

Error in startup script: invalid command name "tk_messagebox"
while executing
"tk_messagebox "
(file "/tmp/NATS_watchdog_screen_popup" line 1)

the content of the script file as follows;


-default ok -icon warning -message "test" -title "TEST" -type ok

hope this helps.

Thanks

Alf
 
You may need to upgrade Tcl/Tk. I'm using 8.4 (I think 8.5 is out already). The messagebox widget may be newer than 8.3.

_________________
Bob Rashkin
 
Alf -

wish83 handles tk_* cmds just fine.

Check your punctuation, it s/b tk_messageBox

Try this from the wish console window :

% tk_messageBox -message "Testing 123!" -type ok

You should see the message box ...



 
hello cptk,

thanks for that. That does work ok! My lack of understanding let me down. Cptk, this bit is great, but can I launch the same message without having to enter into the wish console. I want to be able to launch a popup from within a unix script file, ksh, and therefore would like to issue the wish executable with command line parameters depending on a certain condition. I think I have read somewhere you can supply the command line parameters in a test file and then pass the name of the text file to the wich executable. If you can offer any help, I'd appreciate it.

Thanks

Alf
 
Hello cptk,

I have worked out the following syntax works.

wish /tmp/NATS_watchdog_screen_popup

(where wish is the binary and then the location and name of the tk_messageBox parameter file)

Would you agree this is the nest syntax?

Thanks

Alf
 
alf -

It's has been some time since I've worked with tcl/tk on a daily basis, but I'll try to help you.

To answer your post "16:35" question, yes you can run any tcl/tk cmd without running the wish console interactively, BUT you need to setup correctly ...

I've provided an example ksh script demonstrated with two methods using two different sample#.tcl scripts.

To test each method, just comment out the other "x" variable line in the ksh script.

Let me know if this is what you where driving at or if you have any question ...


######################
START ksh script
######################

#! /bin/ksh

trap "tput sgr0; echo \"...script terminated!!\"; exit" 1 2 15


function display_rply {
echo "User's repsonse is: $1"
}

### Run a quick tcl script from within a ksh script, ###
### and return the result to ksh script. ###

### There's Two methods to do this... ###
### Method #1: ###
### Executes another ksh script, which in turn ###
### executes tcl/tk and the tk cmds. ###
### Method #2: ###
### Execute tcl/tk directly and run tk script. ###


### used to send an argument to tk (optional)
msgtxt="Which have you decide?"

### Method #1
#x=`/yourfilepath/sample2.tcl`

### Method #2 (with optional argument(s) passed to tk)
x=`/yourwishpath/wish83 /yourfilepath/sample3.tcl "$msgtxt"`

### just to demonstrate a ksh function call
display_rply $x

echo "Response is ... $x"

######################
END ksh script
######################



######################
START sample2.tcl
######################
#! /bin/ksh
# the next line restarts using wish8.3 version \
exec /yourwishpath/wish83 "$0" "$@"

wm iconify .

puts [tk_messageBox -message "testme" -type yesnocancel]
exit
######################
END sample2.tcl
######################



######################
START sample3.tcl
######################
wm iconify .

set ua [lindex $argv 0]
puts [tk_messageBox -message $ua -type yesnocancel]
exit
######################
END sample3.tcl
######################

 
Hello cptk,

just to let you know, what you provided was ideal for me. I made some minor adjustment after first understanding what was going on. Many thanks for this.

Cptk, just one more thing, is there a date/time function that can be called with TK. I would like to be able to record the current date and time when the popup is created on the screen, as part of the text within the tk_messageBox message.

Any help would be appreciated

Thanks

Alf
 
Use plain old date cmd, or ...

For formatted dates, try using the clock cmd ...

> clock format [clock seconds] -format "%d/%m/%y %H:%M
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top