Jump to content
Sign in to follow this  
MattM

Define multiple variables in one panel?

Recommended Posts

Hi,

 

Is it possible to create one panel for the user to define variables or sets?

 

Alternatively, instead of a panel - is it possible to create a pop-up window with a table that requires input for each variable before you can continue?

 

At the moment I am using this kind of code for the user to input values:

 

set value 1 [hm_getint "value 1" "value 1"]
set value 2 [hm_getint "value 2" "value 2"]

 

However this gets very tedious after having to go through 5+ panels clicking proceed each time

 

Thanks

Share this post


Link to post
Share on other sites

Hi,

if you don't want to click "proceed" many times, using hm_getstring

example:

 

set list_of_values [hm_getstring "Values = " "Enter values separated by space" ]

lassign $list_of_values value1 value2 ...

Share this post


Link to post
Share on other sites

Thanks tinh,

 

But what if the values aren't related to each other?

 

For example, I'm thinking about creating a utility to create PBUSH cards based off Huth formula. For this you need to input information such as the type of fastener (e.g. Bolt, Rivet), if the bolt is countersunk or protruding, type of Material (or input Young's Modulus and Shear modulus of bolt material), Diameter of Fastener.

 

It would be great if I could create a custom panel or input tk table with these options. 

Share this post


Link to post
Share on other sites

Hi

To create custom panel, use command hm_framework

To create tk table, use command table

 

at least, you can use if...else to control cases

 

Or make a toplevel, some entries to input values

Relevant commands are toplevel, frame, entry, label, pack, place, grid

Tk table is more complex

Share this post


Link to post
Share on other sites

I've looked into your suggestions and I feel like the tk table is the best way.

 

I've just started trying to construct a table, and I'm getting some errors: namely, frame1 already exists in parent. Not sure where I have gone wrong...

 

#User Input
hwt::CreateWindow mytoplevel \
-windowtitle "Input Fastener Properties" \
-noGeometrySaving \
-cancelButton Cancel \
-acceptButton OK \
-acceptFunc applyFunction \
-defaultButton Accept \
-minsize 470 100 \
-post;
proc applyFunction args {tk_messageBox -message "Fastener Diameter Chosen: $::valueToPrint \
Fastener Type Chosen: $::fromPopDown"}

set recess [::hwt::WindowRecess mytoplevel];
set section2 [label $recess.section2 \
-text "Please Input Fastener Properties" \
-justify left \
-anchor nw \
-font [hwt::AppFont]];

pack $section2 -side top -anchor nw -pady 5;
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 EntryWidget [ AddEntry $recess.frame1 \
-textvariable valueToPrint \
-label "Diamater:" \
-labelWidth 40 \
-entryWidth 20 \
-anchor nw\
-validate real\
-text 5 \
-withoutPacking]; 
pack $EntryWidget -side top -anchor nw -pady 5;           
AddPadding $frame1 -side top -hegiht [hwt::DluHeight 4];

set frame2 [frame $recess.frame2];
pack $frame2 -side top -anchor nw;
AddPadding $frame2 -side top -height [hwt::DluHeight 4];

variable dropDownList; set dropDownList [list Bolt Rivet ];

set entry2 [ AddEntry $recess.frame2 \
-label "Select Fastener Type:" -labelWidth 40 \
-text "Bolt"\
-entryWidth 20 \
-listVar fromPopDown noTyping dropDownList \
-state normal ];
pack $entry2 -side top -anchor nw;
AddPadding $recess.frame2 width 22 -side left; 

 

Share this post


Link to post
Share on other sites
On 4/8/2016 at 2:47 PM, tinh said:

Hi, at EntryWidget, change frame1 to entry1

At entry2, change frame2 to entry2

 

 

Thanks tinh, this works.

 

I'm having trouble with the listvar. In the tk message box I want to report what the user has chosen (at the moment, this is really just a debugging thing for me to see if it works). It works OK with the text variable 'valueToPrint', but if I use 'dropDownList' then it shows both choices and not the one that the user has chosen. If I use 'fromPopDown' as the code above, it gives error reading as there's no such variable..

 

Also, somewhat unrelated... but how can you make your text appear on a new line in a tk message box? I thought this is what '\' does, but apparently not. I.e. I want the tk message box in the code above to looking like:

 

Fastener Diameter Chosen: 

Fastener Type Chosen:

Share this post


Link to post
Share on other sites
1 hour ago, MattM said:

 

Thanks tinh, this works.

 

I'm having trouble with the listvar. In the tk message box I want to report what the user has chosen (at the moment, this is really just a debugging thing for me to see if it works). It works OK with the text variable 'valueToPrint', but if I use 'dropDownList' then it shows both choices and not the one that the user has chosen. If I use 'fromPopDown' as the code above, it gives error reading as there's no such variable..

 

Also, somewhat unrelated... but how can you make your text appear on a new line in a tk message box? I thought this is what '\' does, but apparently not. I.e. I want the tk message box in the code above to looking like:

 

Fastener Diameter Chosen: 

Fastener Type Chosen:

 

 

 

Hi,

to pop up selected value, specify -textvariable when create entry by "AddEntry" command

then selected value is assigned to this -textvariable

 

 

Share this post


Link to post
Share on other sites

Ah thanks, I thought listvar and textvariable were doing the same thing.

 

One final thing.. how do I make the window close after the user presses OK?

 

Edit:  Actually I will use tkmessageBox -type okcancel.

What I want is that if the user presses OK it will accept the variables and also close the main window where it asks for inputs. If the user presses cancel then it will close the tkmessageBox and revert back to the main window asking for the inputs.

 

I guess I need something else in the applyFunctrion procedure in order to close the main dialouge box when OK is pressed?

 

hwt::CreateWindow mytoplevel \
-windowtitle "Input Fastener Properties" \
-noGeometrySaving \
-cancelButton Cancel \
-acceptButton OK \
-acceptFunc applyFunction \
-defaultButton Accept \
-minsize 470 100 \
-post;
proc applyFunction args {tk_messageBox -message "Fastener Diameter Chosen: $::valueToPrint \ 
Fastener Type Chosen: $::fastType" -type okcancel}

Share this post


Link to post
Share on other sites

Hi,

 

proc applyFunction args {

set answer [tk_messageBox -message "Fastener Diameter Chosen: $::valueToPrint \ 
Fastener Type Chosen: $::fastType" -type okcancel]

if {$answer=="ok"} {UnpostWindow .mytoplevel}

}

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
You are posting as a guest. If you have an account, please sign in.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...