Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi all: I try to understand how to

Status
Not open for further replies.

stewang

Programmer
Aug 21, 2003
77
NZ
Hi all:
I try to understand how to use uplevel.
In my program, I create a button in a frame first,
then I add a notifier to the button, if I click on the
button, it will bring up a new window with a listbox,
and a text in the right side of the listbox. But when
I click on the button, I can not see new window come out.

Would anyone help me, please.

Code:
button .b -text "button" -bg white -command { }
pack .b -side top
proc check {} {

toplevel .w

listbox .w.g -text "test"
pack .w.g -side right

}
 
You have 2 problems (neither, by the way has anything to do with "uplevel"; I think you meant "toplevel").
1. In your button creation, you have "-command {}". Basically, you've said the button has no action. Change it to "-command check".
2. The "-text" option is not valid for a listbox. Either change .w.g to a textbox, or change the option to -listvariable and specify a valid list, "listbox .w.g -textvariable tlist; set tlist {test test test test}".

I think for the purposes of this example, you want a textbox anyway.

Bob Rashkin
rrashkin@csc.com
 
Hi Bong:
I try to use your idea to write the code again, but it failed, it complains that the textbox, -textvarible are invaild name, and I could not find the textbox in tcl/tk menu. I also try use label and -text, it work, but that is not what I want, I want a textbox, Please help me fix the problem.

I write four methods as follow, but three of them do not work, just method of two work.

1> I let .w.g go to label, and use option -textvarible.
when I click on the button, it come up a window without
text. please tell me why.

button .b -text "button" -bg white -command check
pack .b -side top

proc check {} {

toplevel .w
label .w.label -textvariable tv; set tv { test test test }
pack .w.label -side top

}


2> I let .w.g go to label, and use option of -text, then it work, it come up a window with a text, when I click the button.it works, but this is not what I want.

Code:
button .b -text "button" -bg white    -command check 
pack .b -side top

proc check {} {

  toplevel .w
  label .w.label -text "test" 
  pack .w.label -side top

}


3> when I put .w.t go to textbox, it complains that the textbox is invaild name, and I could not find the textbox in tcl/tk menu. But this purpose is what I want to use, please tell me what's wrong with my code in here.

Code:
button .b -text "button" -bg white    -command check 
pack .b -side top

proc check {} {

  toplevel .w
  textbox .w.t -listvariable listV; set listV { test test } 
  pack .w.label -side top

}

4> I use listbox and -textvariable in here, but it complains
that the -textvarible is invalid name.

Code:
button .b -text "button" -bg white    -command check 
pack .b -side top

proc check {} {

  toplevel .w
  listbox .w.g -textvariable tlist; set tlist {test test test test} 
  pack .w.label -side top

}
 
Sorry, my mistake.

1. use a textbox, which is the "text" widget:
text .w.g -text test

or

2. use a listbox (I erroneously told you to use "textvariable" when I meant "listvariable"):
listbox .w.g -listvariable tlist
set tlist {test1 test2 test3}

Bob Rashkin
rrashkin@csc.com
 
Code:
Hi Bong:
I add use your idea again into my code, but it still not work, would you find out why for me?
The problem as follow;

1> It complains that the -text is unknown option, but I checked the format and the space already, they looks ok, but why it still complains?

button .b -text "button" -bg white    -command check
pack .b -side top

proc check {} {

  toplevel .w
  text .w.t -text "text"   pack .w.t -side top

}

2> I use listbox in here, but it just come uo a farme without any text.

button .b -text "button" -bg white    -command check
pack .b -side top

proc check {} {

  toplevel .w
  listbox .w.l -listvariable listV 
  set listV { test test }
  pack .w.l 

}
 
OK. My mistake again. For the text widget, indeed, -text is not an option. You need to use ".w.t insert end "text"".
For the listbox, the variable, listV, is local to the procedure, check. You need to declare listV in the main program, or set it as global in the proc ("global listV"), or use the global scope explicitly :):listV).

Bob Rashkin
rrashkin@csc.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top