LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-24-2005, 08:15 PM   #1
Kenji Miyamoto
Member
 
Registered: Dec 2004
Distribution: Mandrake 10.1; Fedora Core 3; FreeBSD 5.3; Slackware 10.1 (2.6.10);
Posts: 234

Rep: Reputation: 30
Tk: Storing Output of Program


How would one store the output of a program to a variable in a Tk shell script? Also, how would one embed the output into a label?
 
Old 06-24-2005, 09:48 PM   #2
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
I assume you're actually using TCL/TK (TK runs with multiple languages). To set a variable to the output of a program:

set somevariable [exec program]

To set a label to the value of the variable, use the -textvariable option. For example:

Code:
label $base.lab23  -anchor nw \
       -background #d3d3d3 -borderwidth 0  \
       -font {Fixed -14 bold} -height 20 \
       -justify left -padx 4  -relief raised \
       -textvariable somevariable -width 260 \
       -foreground #000000
 
Old 06-25-2005, 12:38 AM   #3
Kenji Miyamoto
Member
 
Registered: Dec 2004
Distribution: Mandrake 10.1; Fedora Core 3; FreeBSD 5.3; Slackware 10.1 (2.6.10);
Posts: 234

Original Poster
Rep: Reputation: 30
How would I position an object, such as a button, next to another one, rather than below?
 
Old 06-25-2005, 12:54 AM   #4
macemoneta
Senior Member
 
Registered: Jan 2005
Location: Manalapan, NJ
Distribution: Fedora x86 and x86_64, Debian PPC and ARM, Android
Posts: 4,593
Blog Entries: 2

Rep: Reputation: 344Reputation: 344Reputation: 344Reputation: 344
You can use the place command, with explicit x-y coordinates. For example:

Code:
    place $base.but44 \
        -x 90 -y 585 -anchor nw -bordermode ignore
    place $base.but45 \
        -x 190 -y 585 -anchor nw -bordermode ignore
    place $base.but46 \
        -x 290 -y 585 -anchor nw -bordermode ignore
This will place three buttons horizontally next to each other (the "-y" values are the same, but the "-x" values position them along the line).
 
Old 06-25-2005, 01:57 AM   #5
Kenji Miyamoto
Member
 
Registered: Dec 2004
Distribution: Mandrake 10.1; Fedora Core 3; FreeBSD 5.3; Slackware 10.1 (2.6.10);
Posts: 234

Original Poster
Rep: Reputation: 30
The problem here is that the window always changes size, and the buttons don't push the bottom of the window down, so they often don't appear:
Code:
#!/usr/bin/wish
# Set the fortune into place
set fortune [exec fortune]
frame .mainFrame -width 300 -height 300
message .mainFrame.fort -text $fortune # Fortune text
button .close -command "destroy ." -text "Close" # Exit button
button .next -text "Next" -command "newFortune" # Next fortune button
pack .mainFrame
pack .mainFrame.fort
place .next -x 90 -y 100 -anchor nw -bordermode ignore
place .close -x 190 -y 100 -anchor nw -bordermode ignore
# In case another fortune is wanted
proc newFortune {} {
	set fortune [exec fortune]
	destroy .mainFrame.fort
	message .mainFrame.fort -text $fortune
	pack .mainFrame.fort
}
Is there a way to place them horizontally beside each other, but still alow them to slide downward for longer messages?

Last edited by Kenji Miyamoto; 06-25-2005 at 09:24 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is the unix mail program storing mailboxes lmcilwain Linux - Software 2 12-02-2005 11:46 AM
Password storing program? Ariod Linux - Software 2 09-09-2005 06:25 PM
why output is wrong ( C Program ) minil Programming 7 02-23-2005 06:05 AM
C function to execute a program and return the output of the program ryan.n Programming 4 08-14-2004 10:11 PM
getting output from a program executed from c++ dfuse Programming 6 08-22-2003 02:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration