Justify button text to left in TCL TK - tcl

I'm trying to build Gui with Tcl.tk and use it inside ICC (Synopsys).
Problem: All texts are justify to center instead of left.
every creation of "checkbutton" show text at center.
How can I order texts to be justify left side?
How can I disable halo around "checkbutton"?
package require Tk 8.4
set default_font *adobe*helvetica*bold-r-normal*12*
option add *font $default_font
option add *background #D4D0C8
option add *foreground #000000
option add *activeBackground #ececec
option add *activeForeground #100
option add *selectBackground #c3c3c3
option add *disableForeground #a3a3a3
option add *troughColor #c3c3c3
option add *highlightBackground #d9d9d9
option add *width 2
proc ttt {} {
set mainWin ".win"
destroy $mainWin
toplevel $mainWin -padx 1 -pady 1
wm title $mainWin "Aviadz Tools"
wm geometry $mainWin +50+50
wm resizable $mainWin 1 1
frame $mainWin.top -borderwidth 1
pack $mainWin.top -side top -fill x -ipadx 200 -ipady 300 -anchor nw
labelframe $mainWin.top.icc -text " ICC " -fg blue -padx 5 -pady 5
pack $mainWin.top.icc -side top -anchor nw
place $mainWin.top.icc -x 1 -y 1 -width 300 -height 160
place [checkbutton $mainWin.top.icc.change_name -background grey -text "Change names" -justify left] -x 1 -y 0
place [checkbutton $mainWin.top.icc.vout -background grey -text "Verilog Out" -justify left] -x 1 -y 30
place [checkbutton $mainWin.top.icc.defout -background grey -text "DEF Out" -justify left] -x 1 -y 60
place [checkbutton $mainWin.top.icc.copy_mw_lib -background grey -text "Copy MW Lib" -justify left] -x 1 -y 90
pack $mainWin.top.icc.change_name $mainWin.top.icc.vout $mainWin.top.icc.defout
$mainWin.top.icc.copy_mw_lib -anchor w
button $mainWin.start -background green -text "Start" -command start
place $mainWin.start -x 158 -y 250
pack $mainWin.start -side bottom -fill x
}

You can place the text inside a widget with the anchor option like:
button .c -text "Test" -width 100 -anchor w

Related

Tk/Tcl scale widget interval issue

I'm building a scale widget going from 10 to 100 with a spacing (interval) of 10.
When the resolution=1 the result is:
scale widget with resolotion=1
But when the resolution=3 the scale is going from 9 to 99 and no more 10->100,
the results is showed here:
scale widget with resolution=3
The code is:
#!/bin/sh
####################################################################### \
exec /sw/freetools/tk/8.5.6/Linux/rh5/x86_64/bin/wish8.5 "$0" ${1+"$#"}
package require Tk
font create FONT1 -family {DejaVu Sans Mono} -size 7 -weight normal
font create FONT2 -family {DejaVu Sans} -size -8 -weight normal -slant roman
ttk::style configure rule1.TCombobox -background lavender \
-foreground black \
-fieldbackground mistyrose2 \
-padding 0.5
ttk::style map rule1.TCombobox -fieldbackground [list readonly gray98]
frame .frame_F1 -background gray98 -highlightbackground black -highlightthickness 1
frame .frame_F1.top -background gray98 -highlightbackground red -highlightthickness 0
frame .frame_F1.bottom -background gray98 -highlightbackground blue -highlightthickness 0
pack .frame_F1 -padx 10 -pady 10
pack .frame_F1.top -side top -anchor w
pack .frame_F1.bottom -side bottom -anchor w
label .frame_F1.bottom.scale_text1 -text "scale" -foreground black -background gray98 -font FONT1 -justify left
entry .frame_F1.bottom.scale_value -textvariable ::SCALE -foreground black -width 5 -justify right -state readonly
scale .frame_F1.top.scale -orient horizontal \
-variable ::SCALE \
-length 210 \
-from 10 -to 100 \
-tickinterval 10 \
-resolution 1 \
-showvalue false \
-background gray98 \
-font FONT2 \
-foreground black \
-width 12 \
-highlightthickness 0 \
-borderwidth 2 \
-sliderrelief groove \
-sliderlength 18
pack .frame_F1.top.scale
grid .frame_F1.bottom.scale_text1 -column 0 -row 1
grid .frame_F1.bottom.scale_value -column 1 -row 1
How to correct this and to have from 10 to 100 ?

How to add a scrollbar to tcl frame

I am creating a list of radiobuttons on a frame, the list eventually becomes huge and its difficult for user to select items.
Is there anyway i can add a scrollbar to this frame?
I tried adding listbox, but no help.
This is my code.
frame .top.d.b -width 100 -height 20 -borderwidth 2 -relief raised
label .top.d.b.l1 -font fontTEMP_varwidth -text "Comparision Libraries" -anchor center -padx 2 -pady 4
set whu .top.d.b
grid .top.d.b -row 7 -column 2 -sticky nsew
grid .top.d.b.l1 -row 1 -column 2
set w 0
foreach elem $mylist {
radiobutton .top.d.b.$w -text $elem -command [list selectlib $elem $w] -value $elem.abc -padx 2 -pady 2
grid .top.d.b.$w -row $a -column $r -sticky w
incr a
incr w
}
} else {
puts "STD_CELLS_LIBPATH not found\n"
}
}
You can use a canvas combined with scrollbars, than you put your widgets on the canvas. Example:
#!/usr/bin/env wish
ttk::frame .frAlles
# create canvas with scrollbars
canvas .frAlles.c -width 400 -height 200 -xscrollcommand ".frAlles.xscroll set" -yscrollcommand ".frAlles.yscroll set"
ttk::scrollbar .frAlles.xscroll -orient horizontal -command ".frAlles.c xview"
ttk::scrollbar .frAlles.yscroll -command ".frAlles.c yview"
pack .frAlles.xscroll -side bottom -fill x
pack .frAlles.yscroll -side right -fill y
pack .frAlles.c -expand yes -fill both -side top
# create frame with widgets
ttk::frame .frAlles.c.frWidgets -borderwidth 1 -relief solid -width 340 -height 700
for {set i 0} {$i <=20} {incr i} {
ttk::label .frAlles.c.frWidgets.lb$i -text "Label $i:"
ttk::entry .frAlles.c.frWidgets.en$i
ttk::button .frAlles.c.frWidgets.bt$i -text "Button $i" -command exit
grid .frAlles.c.frWidgets.lb$i -padx 2 -pady 2 -row $i -column 0
grid .frAlles.c.frWidgets.en$i -padx 2 -pady 2 -row $i -column 1
grid .frAlles.c.frWidgets.bt$i -padx 2 -pady 2 -row $i -column 2
}
# create frame with buttons
ttk::frame .frAlles.c.frButtons -borderwidth 1 -relief solid -width 340 -height 40
ttk::button .frAlles.c.frButtons.btOK -text "OK" -command exit
ttk::button .frAlles.c.frButtons.btAbbruch -text "Abbruch" -command exit
pack .frAlles.c.frButtons.btOK -padx 2 -pady 2 -side left
pack .frAlles.c.frButtons.btAbbruch -padx 2 -pady 2 -side left
# place widgets and buttons
.frAlles.c create window 0 0 -anchor nw -window .frAlles.c.frWidgets
.frAlles.c create window 200 650 -anchor c -window .frAlles.c.frButtons
# determine the scrollregion
.frAlles.c configure -scrollregion [.frAlles.c bbox all]
# show the canvas
pack .frAlles -expand yes -fill both -side top
Only widgets that implement Tk's scrolling protocol can be associated with a scrollbar; frames are not such a widget.
However, you can put your frame inside a canvas (via the “widget” canvas item type) and canvases are scrollable provided you tell the canvas what the scroll region is. You'll want to make sure that the frame and its contents are children of the canvas in order for the clipping of them to work right.
You can't do that. Only widgets that have scrollcommand options (-xscrollcommand, -yscrollcommand) and xview / yview widget commands can be scrolled.
The answer is late but colud help others.
You could think of using Bwidgets it has many widgets like scrolled windows, frames. https://wiki.tcl-lang.org/page/BWidget

Not able to scroll down in notebook

I created a tcl notebook, it have two tabs, if the file is too big, i am not able to scroll down. Sharing my code here.
To execute this code, you need 2 files (Warning.txt and Error.txt), place them into same directory before running this code.
Please create two files Error.txt and Warning.txt.
Put some content to it make it some 10,000 lines.
#!/usr/bin/wish -f
#
package require Tk
proc noteb {} {
global rundir logfile
frame .lpo
pack .lpo -side top -fill both -expand true
#cd $rundir
set ft [exec grep -c Warning ./Warning.txt]
puts $ft
set ert [exec grep -c Error ./Error.txt]
puts $ert
pack [frame .fa] -fill both -side top
pack [ttk::notebook .fa.nb] -fill both
set gt "Errors"
set bt "Warnings"
set delim ":"
set rt [concat [string trim $bt][string trim $delim][string trim $ft]]
set dt [concat [string trim $gt][string trim $delim][string trim $ert]]
if {$ft > 0} {
.fa.nb add [frame .fa.nb.f1] -text $rt
} else {
.fa.nb add [frame .fa.nb.f1] -text "Warnings"
}
pack [frame .fa.nb.f1.f11] -side top -fill both -expand true
pack [text .fa.nb.f1.f11.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 -relief raised -setgrid true ] -side left -fill both -expand true
scrollbar .fa.nb.f1.f11.scroll -command {.fa.nb.f1.f11.t1 yview}
pack .fa.nb.f1.f11.scroll -side right -fill y
set fp1 [open Warning.txt r]
set v [read $fp1]
.fa.nb.f1.f11.t1 insert 1.0 $v
close $fp1
if {$ert > 0} {
.fa.nb add [frame .fa.nb.f2] -text $dt
} else {
.fa.nb add [frame .fa.nb.f2] -text "Errors"
}
pack [frame .fa.nb.f2.f11] -side top -fill both -expand true
pack [text .fa.nb.f2.f11.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 -relief raised -setgrid true ] -side left -fill both -expand true
scrollbar .fa.nb.f2.f11.scroll -command {.fa.nb.f2.f11.t1 yview}
pack .fa.nb.f2.f11.scroll -side right -fill y
set fp [open Error.txt r]
set c [read $fp]
.fa.nb.f2.f11.t1 insert 1.0 $c
close $fp
}
button .mn -text summary -command {noteb}
pack .mn -side left
In these lines below, you tell the scrollbar about the text widget, but not the text widget about the scrollbar. You need to do both.
pack [text .fa.nb.f1.f11.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 -relief raised -setgrid true ] -side left -fill both -expand true
scrollbar .fa.nb.f1.f11.scroll -command {.fa.nb.f1.f11.t1 yview}
pack .fa.nb.f1.f11.scroll -side right -fill y
Let that instead become this:
text .fa.nb.f1.f11.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 \
-relief raised -setgrid true -yscroll {.fa.nb.f1.f11.scroll set}
scrollbar .fa.nb.f1.f11.scroll -command {.fa.nb.f1.f11.t1 yview}
pack .fa.nb.f1.f11.t1 -side left -fill both -expand true
pack .fa.nb.f1.f11.scroll -side right -fill y
Though I'd actually be inclined to do this instead:
set w .fa.nb.f1.f11
text $w.t1 -bg LightYellow -borderwidth 2 -width 80 -height 6 -relief raised \
-setgrid true -yscroll [list $w.scroll set]
scrollbar $w.scroll -command [list $w.t1 yview]
pack $w.t1 -side left -fill both -expand true
pack $w.scroll -side right -fill y
Putting the container widget name in a variable helps keep your code more sensible, and makes it more obvious that the text and scrollbar are related. (It also makes it easier to refactor the code, if desired.)
I think it will work if you set the -yscroll option on the text widget.

TCL: Displaying multiple widgets in same frame area

I am developing a Tcl based ui. I have couple of buttons on my main window. With each button action, i wanted to show a widget in same tcl frame, and also it should be be overwritten with another widget when button 2 is clicked.
Any example link will be appreciated.
Here goes my code for complete widget.
####################################################################################
package require Tk
set model_type None
wm title . "Impetus interactive: MXL Library Validation Tool V1.0"
wm iconname . "LibValidation"
wm geometry . +150+250
##+######################################################
## Set the COLOR SCHEME for the WINDOW ---
## and background colors for its WIDGETS.
##+######################################################
# set Rpal255 200
# set Gpal255 200
# set Bpal255 255
##set Rpal255 210
##set Gpal255 210
##set Bpal255 210
##set hexPALcolor [format "#%02X%02X%02X" $Rpal255 $Gpal255 $Bpal255]
#tk_setPalette "$hexPALcolor"
## Set color background for some WIDGETS.
##set scaleBKGD "#f0f0f0"
# set radbuttBKGD "#c0c0c0"
# set chkbuttBKGD "#c0c0c0"
# set listboxBKGD "#f0f0f0"
set entryBKGD "#f0f0f0"
set textBKGD "#f0f0f0"
##Set (temporary) FONT-NAMES.
##
## We use a VARIABLE-WIDTH FONT for LABEL and BUTTON widgets.
##
## We use a FIXED-WIDTH FONT for TEXT widgets (to preserve
## alignment of columns in text), LISTBOXES (to preserve
## alignment of characters in lists), and ENTRY fields
## (to make it easy to position the text cursor at narrow
## characters like i, j, l, and the number 1).
##+##########################################################
font create fontTEMP_varwidth \
-family {comic sans ms} \
-size -14 \
-weight bold \
-slant roman
font create fontTEMP_SMALL_varwidth \
-family {comic sans ms} \
-size -12 \
-weight bold \
-slant roman
font create fontTEMP_fixedwidth \
-family {liberation mono} \
-size -14 \
-weight bold \
-slant roman
font create fontTEMP_SMALL_fixedwidth \
-family {liberation mono} \
-size -12 \
-weight bold \
-slant roman
##+###########################################################
## Set GEOMETRY PARAMETERS for the various widget definitions.
## (e.g. width and height of canvas, and padding for Buttons)
##+###########################################################
## CANVAS geom parms:
##set initCan1WidthPx 200
#set initCan1HeightPx 150
##set initCan2WidthPx 255
##set initCan2HeightPx 255
# set BDwidthPx_canvas 2
##set BDwidthPx_canvas 0
## LABEL geom parameters:
set PADXpx_label 0
set PADXpx2_label 1
set PADYpx_label 0
set PADYpx2_label 1
set BDwidthPx_label 2
## BUTTON geom parameters:
set PADXpx_button 0
set PADYpx_button 0
set BDwidthPx_button 2
set PADXpx2_button 2
set PADXpx3_button 3
set PADYpx2_button 2
set PADYpx3_button 3
set BDwidthPx2_button 2
set PADXpx4_button 1
set PADXpx5_button 1
set PADYpx4_button 1
set PADYpx5_button 1
## SCALE geom parameters:
##set BDwidthPx_scale 2
#set initScaleLengthPx 300
##set scaleWidthPx 10
## ENTRY geom parameters:
set BDwidthPx_entry 2
set BDwidthPx_entry2 2
set initImgfileEntryWidthChars 25
##+###################################################################
## DEFINE *ALL* THE FRAMES:
##
## Top-level : '.fRbuttons' '.fRfile' 'fRfile2' '.fRimages'
##
## Sub-frames: '.fRimages.fRcanvas1' '.fRimages.fRcanvas2'
##+###################################################################
## FOR TESTING: (to check frame sizes as window is resized)
set BDwidth_frame 2
set RELIEF_frame flat
set BDwidth_frame 0
set RELIEF_frame flat
frame .top -borderwidth 10
pack .top -side top -fill both
frame .fRbuttons -relief $RELIEF_frame -borderwidth $BDwidth_frame
frame .fRfile -relief $RELIEF_frame -borderwidth $BDwidth_frame
################################################################################
##image create photo img -file "maxL.gif"
canvas .top.myCanvas -background white -width 100 -height 50
pack .top.myCanvas -side top -anchor nw -fill none -padx 2 -pady 2
set myImage [image create photo]
$myImage read "/home/dshaikh/Library_Val/FF_0.99v_125/maxL.gif"
.top.myCanvas create image 55 30 -image $myImage
#####################################################################################
menu .mbar
. configure -menu .mbar
menu .mbar.fm -tearoff 0
.mbar add cascade -menu .mbar.fm -label FILE \
-underline 0
menu .mbar.hm -tearoff 0
.mbar add command -label HELP \
-underline 0 -command {popup_msgVarWithScroll .topHelp "$HELPtext"}
menu .mbar.fm.sb
.mbar.fm.sb add command -label List
.mbar.fm.sb add command -label Bookmarks
.mbar.fm.sb add command -label Mail
labelframe .top.ff -font fontTEMP_varwidth -text "Input and Run options" -padx 2 -pady 2 -bd 2
button .f -text "Inputs" -relief raised -command {take_inputs}
#pack .f -side left -ipadx 2 -ipady 2 -padx 3 -pady 3
button .v -text "Unit Level" -relief raised -command {Run_Unit_level}
##pack .v -side left -ipadx 2 -ipady 2 -padx 3 -pady 3
button .u -text "Interaction Level" -relief raised -command {Run_Interaction_level}
#pack .u -side left -ipadx 2 -ipady 2 -padx 3 -pady 3
button .l -text "Flow Level" -relief raised -command {Run_Flow_Level}
button .e -text "LogFile" -relief raised -command {show_logfile}
pack .f .v .u .l .e -in .top.ff -fill both -padx 2 -pady 2
pack .top.ff -side left -anchor nw -ipadx 4 -ipady 4 -expand y
#############################################################
########### Creating a logfile area ###################
frame .p
set sum [text .p.log -width 80 -height 10 -borderwidth 2 -background LightYellow -relief raised -setgrid true -borderwidth 6 -relief raised -setgrid true -yscrollcommand {.p.scroll set}]
scrollbar .p.scroll -command {.p.log yview}
pack .p.scroll -side right -fill y
pack .p.log -side right -fill both -expand true
pack .p -side right -fill both -expand true
Thanks
Dan

linking procedure to button

I have now created the same user interface with initially using a gui builder for tcl. However, it became limited in terms of how I could structure my interface and the spacing between widgets. Now that I've created my interface I'm looking to create a procedure block to a specific widget. For example, I would like the quit button to exit the program.
To achieve this I created the following procedure:
proc btnQuit args {
exit
}
This doesn't cause a syntax or runtime error however, when the button is pressed, the program does not exit. This is the simplest case as there are others that are more complex so the -command flag will not apply to all situations.
Thoughts?
Below is my entire code. This is just bringing up the user interface.
#Includes the necessary packages
package require BWidget
package require Tk
namespace eval Main_Menu {}
#DO NOT MODIFY!! Graphical User Interface Code DO NOT MODIFY!!
#Limit the size of window
wm maxsize . 475 180 ;#x-500, y-210
wm minsize . 475 180 ;#x-500, y-210
#[Device name] Test Frame w/ associated check boxes
labelframe .lblfrmSelection -text "Testable Devices" -padx 1 -relief groove -height 175 -width 200
button .btnDualUTA -text "Dual UTA" -padx 5 -anchor "center" -justify "center" -padx 3
button .btnTProbe -text "T-Probe" -padx 5 -anchor "center" -justify "center" -padx 7
button .btnOctal -text "Octal" -padx 5 -anchor "center" -justify "center" -padx 14
button .btnUniversal -text "Universal" -padx 5 -anchor "center" -justify "center"
button .btnQuit -text "Exit" -padx 5 -anchor "center" -justify "center" -padx 18
#Setup second frame with image label
labelframe .lblfrmHWSetup -text "Hardware Setup" -padx 1 -relief groove -height 200 -width 175
image create photo glcomm.gif
label .lblSetup -text "Image goes here"
#*************** Render User Environment ******************
#Create Device Test Interface with check boxes in frame.
place .lblfrmSelection -anchor nw -x 5 -y 1 -width 165 -height 175
place .btnDualUTA -in .lblfrmSelection -x 40 -y 15 -anchor "w"
place .btnTProbe -in .lblfrmSelection -x 40 -y 46 -anchor "w"
place .btnOctal -in .lblfrmSelection -x 40 -y 76 -anchor "w"
place .btnUniversal -in .lblfrmSelection -x 40 -y 106 -anchor "w"
place .btnQuit -in .lblfrmSelection -x 40 -y 136 -anchor "w"
#Create label frame "Hardware Setup"
place .lblfrmHWSetup -anchor nw -x 170 -y 1 -height 175 -width 300
place .lblSetup -in .lblfrmHWSetup -x 171 -y 2
# MODIFY BELOW THIS LINE!! MODIFY BELOW THIS LINE!!
proc btnQuit args {
exit
}
You haven't shown how the button is created, but the -command option is what you need
$ tclsh <<'END'
package req Tk
proc btnQuit args {exit}
button .b -text Quit -command btnQuit
pack .b
END
If your button is already created, you can configure it with the -command option
button .b -text Quit
.b configure -command btnQuit
Note that this looks for the "btnQuit" proc in the global namespace. If you're using namespaces, you have to fully qualify the command name. This will throw an error when you click the button (invalid command name "btnQuit")
namespace eval MySpace {
proc btnQuit args {exit}
}
button .b -text Quit -command btnQuit
In this case, you need
button .b -text Quit -command MySpace::btnQuit
If you need to pass arguments to the btnQuit proc, you'll do something like
button .b -text Quit -command [list btnQuit $local_var1 $local_var2]
or
button .b -text Quit -command {btnQuit $global_var1 $global_var2}
The different quoting mechanisms cause the variables to be substituted at different times:
the first when the button is created;
the second when the button is clicked.