LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-26-2005, 07:45 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: Set Value of Text Widget


What methods are there to set the value of a text widget?

Also, .mainFrame's size keeps changing; how can I keep it constant?
Code:
#!/usr/bin/wish
# Set the fortune 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 newFortune {n} {
	set fortune [exec fortune]
	set date [exec date +%H:%m:%S]
	if {$n == 1} {destroy .mainFrame.textFrame.fort}
	set fort [text .mainFrame.textFrame.fort -yscrollcommand {.mainFrame.textFrame.scroll set} -setgrid true -borderwidth 2 -state disabled -wrap word]
	pack .mainFrame.textFrame.fort -side left -fill both -expand true
	if {$n == 1} {destroy .mainFrame.timeFrame.time }
	label .mainFrame.timeFrame.time -foreground red -text $date
	pack .mainFrame.timeFrame.time
	if {$n == 1} { destroy .mainFrame.piX }
	label .mainFrame.piX -text [winfo geometry .mainFrame]
	pack .mainFrame.piX
}

# Setup Window
wm withdraw .
toplevel .mainFrame -height 900 -width 900
wm title .mainFrame "Fortune"
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 "newFortune 1"

# Finalize display
centerWindow .mainFrame
pack .mainFrame.timeFrame
pack .mainFrame.textFrame
newFortune 0
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

Last edited by Kenji Miyamoto; 06-26-2005 at 07:52 PM.
 
Old 06-26-2005, 08:53 PM   #2
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
Okay, I've fixed the problem with setting the value of the text widget. I still can't seem to get the window to always be the same.
 
  


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
A good simple text display widget in GTK (not Label) vharishankar Programming 3 05-18-2006 05:44 AM
Delete widget in tcl/tk Ephracis Programming 1 02-14-2005 07:31 AM
Rich Text Widget/Database Front End Stranger Programming 5 10-03-2004 06:37 PM
Standard output - Tcl/Tk widget liguorir Linux - Software 0 06-03-2004 01:15 PM
GUI test tool to perform widget functions via a text file liguorir Linux - Software 0 01-05-2004 02:30 PM

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

All times are GMT -5. The time now is 11:00 PM.

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