LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Tcl/Tk: Set Value of Text Widget (https://www.linuxquestions.org/questions/programming-9/tcl-tk-set-value-of-text-widget-337452/)

Kenji Miyamoto 06-26-2005 07:45 PM

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


Kenji Miyamoto 06-26-2005 08:53 PM

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.


All times are GMT -5. The time now is 01:35 PM.