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 export to an external file - please help!

Status
Not open for further replies.

godatguitar

Programmer
May 8, 2003
33
0
0
GB
HI All

I need to send some vaules, (one is called 'mark') to an external file. I.e The value of 'mark' = 16, i need 16 to be in another blank file, possibly a txt file or something. Basically, each of my programs will add another integer/binary value to this file, and another program will read in these values, and add them together and display a 'total mark'.

Could someone please give me an example of how to do this, as I have no idea and cant find out how to do this anywhere.

Many thanks in advance

PAUL
 
Hi Again


I actually can write to the file now, but it overwrites the file each time, ie i will have some contents in the file, and the next time I run it it will overwrite the vaule in the file. My code is:

set data $mark
set fileId [open results.txt "w"]
puts -nonewline $fileId $data
# close the file, ensuring the data is written out before you continue
close $fileId

If anyone can show me where i am going wrong I would be very grateful.

Cheers
 
OK Guys

I figured out it is the same as C, in that instead of "w" I can do "a" and it appends the file, or adds to it.

I need to know how to disable a button once it has been pressed now. Does anyone know how to do this?

Basically, they submit the test, get a result, and now i need the submit button to become disabled.

Cheers
 
when you wish to not overwrite the file use "a" in the open command instead of "w". Append instead of Write.

hope that helps
 
sorry i missed your post about the append solution. When i want a button disabled i usually just bind the click to disable it.


button .button -text "A button" -command "some_function"

bind .button <ButtonPress-1> &quot;.button configure -state disabled&quot;

 
Many widgets, including all forms of buttons, have a -state attribute. Its default value is &quot;normal&quot;, which enables normal function. Setting the -state attribute to &quot;disabled&quot; makes a widget unresponsive to user interaction, and Tk changes the appearance of the widget to indicate the disabled state, usually by &quot;greying it out.&quot;

Here's a quick example:

Code:
button .b -text &quot;Click me&quot; -command {puts &quot;Clicked&quot;}
checkbutton .cb -text &quot;Enable&quot; -variable bState     -onvalue normal -offvalue disabled     -command {.b configure -state $bState}
.cb select
pack .b .cb -anchor w -padx 2 -pady 4

- 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
 
Right, heres an update:

This is the code for the button (it is in a frame) :


button $f.b -text &quot;Submit Answers&quot; -command {

set mark 0

# if the correct answer is chosen

if {$q1 == &quot;0&quot;} {incr mark}

if {$q2 == &quot;1&quot;} {incr mark}

if {$q3 == &quot;2&quot;} {incr mark}

set done 1

set result [expr {$mark * 100/3 }]
set fileId [open tmplgr &quot;a&quot;]
puts -nonewline $fileId &quot;1&quot;
puts $fileId $result
close $fileId


The variable done, is used outside of a proc with:

tkwait variable done

label .r -text &quot;Your Result is $mark out of 3&quot; -fg red
label .l -text &quot;The Correct answers Have been selected for your reference.&quot;

pack .r -padx 0 -pady 0 -anchor n
pack .l -padx 0 -pady 0 -anchor n

#END OF PROGRAM


Now, I can get the button to work fine without becoming disabled, and the program is great. However, when I try to disable the button, when the prog is run ONLY the disabling actually occurs, it does not do anything after:

tkwait variable done

I have tried Binding the button bind $f.b <....>...., I have tried writing other variables and waiting on those, I have also tried writing another proc to disable the button, but to no avail.

Could someone please point me in the right direction!! Many thanks

PAUL (godatguitar)
 
you could put the code for disabling in the -command section. That way when the button is clicked and your -command code would disable to button.
 
ok

how do i do that?


I have tried and it doesnt work

Configure is unrecognised.

Please help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top