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!

How to do this 1

Status
Not open for further replies.

IllegalOperation38

Technical User
Jun 13, 2003
9
0
0
US
Greetings. I would like to know if someone could be so kind as to show me how to do this one thing. Then I can study it and learn, and move on.

I have a simple canvas with a button and a display window.

When you click the button, it sends the command [df -k] which shows disk space usage in Linux, but instead of diplaying the output in the terminal bin/bash I wish it to show in the window on the canvas.

Note I am using wishx that can interpret unix commands directly, unless there was an easier and more practical way.

So far I have

button .b -text "Show Disk Space" -command {system df -k}

Thank you,
and
Kind regards
 
I'm not familiar with wishx but I think this should work:
change "-command {system df -k}" to "-command {set tstr [system df -k]}". Then display the text, $tstr, in the canvas.





Bob Rashkin
rrashkin@csc.com
 
A few additional comments...

First, it's usually best to use either the pack or grid command to manage your GUI. It is possible to use the canvas widget as a geometry manager, but it doesn't handle resizing of its child widget automatically (either in response to window size changes or child size changes), so you have to write all the code to do that properly. Admittedly, there are some occasions where it's handy to use the canvas as a geometry manager; for example, it serves as the basis for a scrollable frame "megawidget." However, if your intent is to create a scrollable frame, it's usually much easier and better to use one of the existing scrollable frame implementations. The Tcl'ers Wiki ( has information about several extensions implementing scrollable frames, including BWidget, and [ignore][incr Widgets][/ignore],
Second, for displaying more than a couple of lines of text, it's easiest to use the text widget. The text widget is a multi-line text display and editing widget, and it supports multiple fonts, colors, embedded images, embedded widgets, and bindings on text. See
Finally, you won't be able to use the system command to do what you want. system (which is a command provided by the TclX extension, not a built-in Tcl command) returns the exit code of the command; it doesn't give you any way to capture the standard output of the command. On the other hand, Tcl has an exec command, which provides the functionality you want. See With it, you could do something like:

Code:
button .b -text "Run" -command {
    set tstr [exec df -k]
}

Something to keep in mind is that exec blocks until the command finishes execution. So, if the command takes 5 minutes to complete, your script is frozen for 5 minutes. This can be particularly bad with a GUI application, as your program's interface will be completely unresponsive during that time. There are ways around this, but we're getting beyond the scope of your original question. If it turns out that you need a non-blocking way to handle the external command execution, we can point you to some information on how to handle it.

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Wow guys, that certainly seems like some good information. I shall put it to work this weekend on my first project (first ever!) and I will report back how well I suceeded.

Indeed programming is difficult to learn over the internet!



Kind regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top