GUI question

Become a member of the CGSociety

Connect, Share, and Learn with our Large Growing CG Art Community. It's Free!

THREAD CLOSED
 
Thread Tools Search this Thread Display Modes
  12 December 2007
Question GUI question

Hello there,

I want to read a string from a textfield and when I click a button pass it to a function. This should be easy enough .. I thought!

It works when I create the window on a global level but not when I do it in a function! Here is my code:


proc test()
{
	if (`window -exists "window1"`)deleteUI -window "window1";
 
	string $wnd = `window -title "Test Window" "window1"`; 
	columnLayout ColumnLayout; 
	   
	$txt = `textField -text "Ready" -editable true -width 278 StatusLine`; 
	$btn = `button -label "Click me"`;
	button -edit -command "print (`textField -query -text $txt`+\"\\n\")" $btn;
	showWindow $wnd; 
	
 }
test();


I guess the problem is that the textfield variable $txt doesnt exist anymore since it was created inside the function. I'm fairly new to mel, could anybody tell me how to do this properly?


Thanks alot in advance!

seb
__________________
www.sebscorner.org
(brandnew and shiny!)
 
  12 December 2007
By properly browsing here I found the solution here :

http://forums.cgsociety.org/showthr...0&highlight=gui

__________________
www.sebscorner.org
(brandnew and shiny!)
 
  12 December 2007
hi seb,

i see that you choose to use "StatusLine" as the name for the textfield. so the following shoud work :
proc test()
{
	if (`window -exists "window1"`)deleteUI -window "window1"; 
	string $wnd = `window -title "Test Window" "window1"`; 
	columnLayout ColumnLayout; 	   
	textField -text "Ready" -editable true -width 278 StatusLine; 
	$btn = `button -label "Click me"`;
	button -edit -command "print (`textField -query -text StatusLine`+\"\\n\")" $btn;
	showWindow $wnd;     
 }
test();


on a general note, i prefer naming all the UI controllers uniquely so we know what they are... when we need to query their values.

and your point that "the textfield variable $txt doesnt exist anymore since it was created inside the function." is right.. since the variables have been declared inside the function, their scope is limited with in it. You can use global variables to hold the names of the controls but thats a v.bad idea to store control names in global vars.
__________________
|| Loka samastaa sukhino bhavantu ||
ash
 
  12 December 2007
Thread automatically closed

This thread has been automatically closed as it remained inactive for 12 months. If you wish to continue the discussion, please create a new thread in the appropriate forum.
__________________
CGTalk Policy/Legalities
Note that as CGTalk Members, you agree to the terms and conditions of using this website.
 
Thread Closed share thread



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
CGSociety
Society of Digital Artists
www.cgsociety.org

Powered by vBulletin
Copyright 2000 - 2006,
Jelsoft Enterprises Ltd.
Minimize Ads
Forum Jump
Miscellaneous

All times are GMT. The time now is 10:47 AM.


Powered by vBulletin
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.