TK GUI TUTORIAL
Hello, I am going thorugh the tutorial for the HW GUI TOOLKIT and I got stock when running it.
The example is as follows:
#
#
#
hwt::CreateWindow mytoplevel \
-windowtitle 'Dialog Title'\
-noGeometrySaving \
-cancelButton Cancel \
-acceptButton OK \
-acceptFunc applyFXN \
-defaultButton Accept \
-minsize 470 300 \
-post;
proc applyFXN {args } {
tk_messageBox -message 'The Createwindow function passes the \
toplevel window to the procedure listed so you must have args \
in the procedure. Args is $args';
destroy $args;
}
set recess [hwt::WindowRecess mytoplevel];
set section1 [label $recess.section1 \
-text 'Section one label '\
-justify left \
-anchor nw \
-font [hwt::AppFont]];
pack $section1 -side top -anchor nw;
hwt::AddPadding $recess -side top -height [hwt::DluHeight 4];
set frame1 [frame $recess.frame1];
pack $frame1 -side top -anchor nw;
hwt::AddPadding $frame1 -side left -width [hwt::DluWidth 4];
set fileSelection [ hwt::AddEntry $frame1.entry1 \
-label 'File Name' \
-labelWidth 15\
-entryWidth 42\
-listProc whenPressed 'dialogBrowse $recess' \
-iconName msfolder \
-iconLoc -1 2 \
-withoutPacking \
-textvariable filename \
-state 'normal' ];
proc dialogBrowse {args} {
variable filename
variable recess
set filename [tk_getOpenFile -parent $recess]
}
pack $fileSelection -side left -anchor nw;hwt::AddPadding $frame1 -side left -width [hwt::DluWidth 4];
set bWidth [hwt::DluWidth 50 [hwt::AppFont]];
set bHeight [hwt::DluHeight 14 [hwt::AppFont]];
set button1 [hwt::CanvasButton $frame1.button $bWidth $bHeight \
-command '[namespace current]::importFile' $recess \
-text import \
-state normal \
-takefocus 1\
-font [hwt::AppFont]];
proc importFile {args} {
tk_messageBox -title 'GUI Checklist' \
-message 'The file has been imported.' \
-icon info \
-parent $args \
-type ok;
}
pack $button1 -side left -anchor nw;
#
#
It is a very simple code that displays a window with a input box to select a file.
I get an error message when running it that says there is no such variable as recess.
Does anybody know where to look for the syntax of the getOpenFile command?
Thanks!
Answers
-
I tested and see it run normally!
Anyway you can try again with variable '::recess' instead of 'recess'. This will link recess to global scope and you need not declare by 'variable recess'
tk_getOpenFile is a tk command, you look for help in Tcl/Tk manual
regards,
tinh
0 -
Thanks!
You are right, it works fine in the script editor, but in the tutorial page it does not.
Once I have completed the script it is not showing the radio buttons.
Do you know what is missing?
hwt::CreateWindow mytoplevel \
-windowtitle 'Dialog Title'\
-noGeometrySaving \
-cancelButton Cancel \
-acceptButton OK \
-acceptFunc applyFXN \
-defaultButton Accept \
-minsize 470 350 \
-post;
proc applyFXN {args } {
tk_messageBox -message 'The Createwindow function passes the \
toplevel window to the procedure listed so you must have args \
in the procedure. Args is $args';
destroy $args;
}
set recess [hwt::WindowRecess mytoplevel];
set section1 [label $recess.section1 \
-text 'Section one label '\
-justify left \
-anchor nw \
-font [hwt::AppFont]];
pack $section1 -side top -anchor nw;
hwt::AddPadding $recess -side top -height [hwt::DluHeight 4];
set frame1 [frame $recess.frame1];
pack $frame1 -side top -anchor nw;
hwt::AddPadding $frame1 -side left -width [hwt::DluWidth 4];
set fileSelection [ hwt::AddEntry $frame1.entry1 \
-label 'File Name' \
-labelWidth 15\
-entryWidth 42\
-listProc whenPressed 'dialogBrowse $recess' \
-iconName msfolder \
-iconLoc -1 2 \
-withoutPacking \
-textvariable filename \
-state 'normal' ];
proc dialogBrowse {args} {
variable recess
variable filename
set filename [tk_getOpenFile -parent $recess ]
}
pack $fileSelection -side left -anchor nw;hwt::AddPadding $frame1 -side left -width [hwt::DluWidth 4];
set bWidth [hwt::DluWidth 50 [hwt::AppFont]];
set bHeight [hwt::DluHeight 14 [hwt::AppFont]];
set button1 [hwt::CanvasButton $frame1.button $bWidth $bHeight \
-command '[namespace current]::importFile' $recess \
-text import \
-state normal \
-takefocus 1\
-font [hwt::AppFont]];
proc importFile {args} {
tk_messageBox -title 'GUI Checklist' \
-message 'The file has been imported.' \
-icon info \
-parent $args \
-type ok;
}
pack $button1 -side left -anchor nw;
hwt::AddPadding $recess -side top -height [hwt::DluHeight 7];
set section2 [label $recess.section2 \
-text 'Section two label' \
-justify left \
-anchor nw \
-font [hwt::AppFont]];
pack $section2 -side top -anchor nw;
hwt::AddPadding $recess -side top -height [hwt::DluHeight 4];
set frame2 [frame $recess.frame2];
pack $frame2 -side top -anchor nw;
hwt::AddPadding $frame2 -side left -width [hwt::DluWidth 4];
set labelWidth 17
set entryWidth 15
set entry1 [hwt::AddEntry $frame2.entry1 \
-label 'Entry field label ' \
-labelWidth $labelWidth \
-entryWidth $entryWidth \
-textvariable [namespace current]::entry1TextVariable \
-validate real \
-state normal \
-withoutPacking];
pack $entry1 -side top -anchor nw;
hwt::AddPadding $frame2 -side top -hegiht [hwt::DluHeight 4];
variable dropDownList; set dropDownList [list Red Blue Green Yellow ];
set entry2 [hwt::AddEntry $frame2.entry2 \
-label 'Combo box label:' -labelWidth $labelWidth \
-text 'Red'\
-entryWidth [expr {$entryWidth -2}]\
-listVar fromPopDown noTyping dropDownList \
-state normal ];
pack $entry2 -side top -anchor nw;
hwt::AddPadding $recess -side top -hegiht [hwt::DluHeight 7];
set section3 [label $recess.section3 \
-text 'Section three label.' \
-justify left \
-anchor nw \
-font [hwt::AppFont]];
pack $section3 -side top -anchor nw;
hwt::AddPadding $recess -side top -hegiht [hwt::DluHeight 4];
set frame3 [frame $recess.frame3];
pack $frame3 -side top -anchor nw;
hwt::AddPadding $frame3 -side left -width [hwt::DluWidth 4];
set rbl [radiobutton $frame3.rb1 \
-text 'Option one'\
-variable '[namespace current]::optionVariable' -value one ];
pack $rb1 -side top -anchor nw;
hwt::AddPadding $frame3 -side top -width [hwt::DluHeight 4];
set rb2 [radiobutton $frame3.rb2 \
-text 'Option two'\
-variable '[namespace current]::optionVariable' -value two ];
pack $rb2 -side top -anchor nw;
hwt::AddPadding $frame3 -side top -width [hwt::DluHeight 4];
set rb3 [radiobutton $frame3.rb3 \
-text 'Option three'\
-variable '[namespace current]::optionVariable' -value two ];
pack $rb3 -side top -anchor nw;Best regards.- Edgar
0 -
I tested it and see 2 radio buttons: 'Option two' and 'Option three'
an error occurred with rb1 when you creating it, you miss writing it as 'rbl' (RBL) !
regards,
tinh
0 -
Very good catch! Thank you so much!.-Edgar
0