LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
 
LinkBack Search this Thread
Old 06-26-2005, 11:29 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
Tcl/Tk Bracket Problems in Command


After several failures, I haven't been able to find a way to get this to work as planned:
Code:
#!/usr/bin/wish
# Set the fortune window into place
proc centerWindow {w} {
	set width 500
	set height 500
	set x [expr { ( [winfo vrootwidth  $w] - $width  ) / 2 }]
	set y [expr { ( [winfo vrootheight $w] - $height ) / 2 }]
	wm geometry $w ${width}x${height}+${x}+${y}
}
proc writeToFile {data} {
	set dataFile "fortune.txt"
	if {[file exists $dataFile] == 1} { file delete $dataFile }
	set fileId [open $dataFile "w"]
	puts -nonewline $fileId $data
	close $fileId
}
proc newFortune {n} {
	# Set data
	set fortune [exec fortune]
	set date [exec date +%H:%m:%S]
	# Display/reset fortunes
	if {$n == 1} {destroy .mainFrame.textFrame.fort}
	set fort [text .mainFrame.textFrame.fort -yscrollcommand {.mainFrame.textFrame.scroll set} -setgrid true -borderwidth 2 -wrap word -relief flat -highlightbackground black -highlightcolor black -exportselection true]
	pack .mainFrame.textFrame.fort -side left -fill both -expand true
	.mainFrame.textFrame.fort insert end $fortune
#	.mainFrame.textFrame.fort configure -state disabled
	# Display/reset time
	if {$n == 1} {destroy .mainFrame.timeFrame.time }
	label .mainFrame.timeFrame.time -foreground red -text $date
	pack .mainFrame.timeFrame.time
	return $fortune
}
# Setup Window
wm withdraw .
toplevel .mainFrame
wm title .mainFrame "Fortune"
centerWindow .mainFrame
wm resizable .mainFrame false false

# Create widgets
frame .mainFrame.timeFrame -pady 5 -padx 5
frame .mainFrame.textFrame -pady 5 -padx 0 -height 30 -width 50
scrollbar .mainFrame.textFrame.scroll -command {.mainFrame.textFrame.fort yview}
frame .mainFrame.buttonFrame -pady 5 -padx 5
button .mainFrame.buttonFrame.close -command "destroy ." -text "Close"
button .mainFrame.buttonFrame.next -text "Next" -command "set fortuneData [newFortune 1]"

# Finalize display
pack .mainFrame.timeFrame
pack .mainFrame.textFrame
set fortuneData [newFortune 0]
#-----
button .mainFrame.buttonFrame.save -text "Save" -command "writeToFile $fortuneData"
#-----
pack .mainFrame.textFrame.scroll -side right -fill y
pack .mainFrame.textFrame.fort -side left -fill both -expand true
pack .mainFrame.buttonFrame
pack .mainFrame.buttonFrame.next -side left
pack .mainFrame.buttonFrame.close -side right
pack .mainFrame.buttonFrame.save -side right
The way I'd like it to work is for $fortuneData to be set to what the function "newFortune" returns. The way I've set newFortune is that to kill the previous .mainFrame.textFrame.fort when a 1 is given to it. I can't give it the 1 and set fortuneData at the same time in the command using any way I've tried.

Does someone else have a solution?
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problems installing Tk (of Tcl/Tk) Arild2 Linux - Software 2 12-14-2007 11:58 PM
Problems installing TCL/TK in Fedora C2 quilop Linux - Software 1 07-09-2004 07:28 AM
execute shell command inside of tcl file khucinx Programming 1 07-05-2004 01:29 PM
Tcl/Tk - command < entry > question. liguorir Linux - Software 0 05-06-2004 10:36 PM
Non-functioning bracket-key dekket Linux - General 1 04-21-2004 06:46 PM


All times are GMT -5. The time now is 05:32 AM.

Main Menu
 
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
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration