TCL: GUI/widget needed for two customized buttons
Hello - I am trying to create a macro, but I want to have customized buttons in a pop-up window rather than yes/no. Here is how I create the yes/no pop-up:
tk_messageBox -title $version -type yesno -message "Ask question here...?"
Do I need a widget instead?
Best Answer
-
<span class="ph Blue">I would personally always work with dialogs. <br /><br />An example of a dialog with custom button can be seen below. <br /><br />if {[winfo exists .d]} {destroy .d} <br /><br />set dlg [::hwtk::dialog .d -title "Custom Buttons"]<br /><br />set f [.d recess]<br /><br />::hwtk::button $f.b1 -text "Text Here" -help "Text only" -command Button1<br /><br />pack $f.b1<br /><br />$dlg buttonconfigure ok -command onOK<br /><br />proc Button1 {} {<br /><br /> puts "Button 1 Success"<br /><br />}<br />proc onOK {} {<br /><br /> .d unpost<br /> puts "Proceed"<br /> <br />}<br /><br />.d post<br /></span>
<span class="ph Blue">Dialogs are very flexible and can contain many different types of base widgets. This should do what you are asking to do. <br /><br />Hope this helps <br /></span>
2
Answers
-
<span class="ph Blue">I would personally always work with dialogs. <br /><br />An example of a dialog with custom button can be seen below. <br /><br />if {[winfo exists .d]} {destroy .d} <br /><br />set dlg [::hwtk::dialog .d -title "Custom Buttons"]<br /><br />set f [.d recess]<br /><br />::hwtk::button $f.b1 -text "Text Here" -help "Text only" -command Button1<br /><br />pack $f.b1<br /><br />$dlg buttonconfigure ok -command onOK<br /><br />proc Button1 {} {<br /><br /> puts "Button 1 Success"<br /><br />}<br />proc onOK {} {<br /><br /> .d unpost<br /> puts "Proceed"<br /> <br />}<br /><br />.d post<br /></span>
<span class="ph Blue">Dialogs are very flexible and can contain many different types of base widgets. This should do what you are asking to do. <br /><br />Hope this helps <br /></span>
2 -
Hello -
Thank you. That worked. How can I customize it to look like the attached pic?
0 -
To match the look of the picture you attached you can do the following...
change the -title option to your preference
change the -text option of the button command to read option 1
add another button with the options you want (make sure to pack this one with the new path name you specify)
Dialogs have the buttons apply, ok, and cancel built into them. You can remove them by using $dlg (variable name you assigned your pathname for the dialog) hide cancel (the button you want to hide) should look like this "$dlg hide cancel"
Make sure you add the command for what you want the buttons to do. Without this the button press will not mean anything.
This should do what you want it to do. I will also point you to our online help https://2021.help.altair.com/2021.2/hwdesktop/altair_help/topics/reference/hwtk/hwtk_dialog.htm . It can be very helpful it is quite thorough.
Hope this helps
1 -
Thank you. That worked well!
0