[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Newbie having trouble with SpecTcl, TkListbox and TkScrollbar

ejb

9/5/2003 6:31:00 AM

I'm trying to learn Tk and SpecTcl.

I created this layout with the SpecTcl tool and then hand modified the
commands in it.

Everything works 'visually'. But, I can't seem to figure out the index
value returned from the list box.

Can anyone point me in the right direction?
-------------------------------------------------------------------
#!/usr/bin/env ruby
# Sample SpecTcl main program for testing GUI
require 'tk'
top = TkRoot.new { title "list_scrl_entry1 test" }
# Interface generated by SpecTcl (Ruby enabled) version 1.1
# File: list_scrl_entry1.ui
# For use with Tk8.1 or later, using the grid geometry manager.
def list_scrl_entry1_ui (root)
@zzentry = TkVariable.new
@zzentry.value = "Opening Text"
hobbies = %w[ Flying Table-Tennis History Reading Writing Programming
Photography
TV Movies Concerts Theater Opera Ballet ]
# Widget creation.
listbox_1 = TkListbox.new(root,
'height' => '6',
'width' => '0',
'selectmode' => 'single',
'exportselection' => 0
)
scrollbar_1 = TkScrollbar.new(root
)
entry_1 = TkEntry.new(root,
'textvariable' => @zzentry,
'borderwidth' => '4',
'state' => 'disabled'
)
# widget commands
listbox_1.insert("end", *hobbies)
listbox_1.yscrollcommand {|y0,yn| scrollbar_1.set(y0,yn)}
# proc { |first,last| scrollbar_1.set first,last }
# %B.scrollbar#1 set
scrollbar_1.configure(
'command' => proc { |*args| listbox_1.yview(*args) }
#%B.listbox_1 yview
)
# Geometry management
listbox_1.grid('in' => root,'column' => 1,'row' => 1,'sticky' =>
'nesw')
scrollbar_1.grid('in' => root,'column' => 2,'row' => 1,'sticky' =>
'ns')
entry_1.grid('in' => root,'column' => 1,'row' => 2, 'sticky' =>
'nesw')
# Container root (rows).
TkGrid.rowconfigure(root, 1, 'weight' => 0, 'minsize' => 26)
TkGrid.rowconfigure(root, 2, 'weight' => 0, 'minsize' => 30)
# Container root (columns).
TkGrid.columnconfigure(root, 1, 'weight' => 0, 'minsize' => 268)
TkGrid.columnconfigure(root, 2, 'weight' => 0, 'minsize' => 14)
# Additional interface code.
print "listbox_1 selection " , listbox_1.curselection, "xx \n"
print "listbox_1 selection " , listbox_1.curselection[0], "xx \n"
print "listbox_1 selection class " , listbox_1.curselection.class,
"\n"
listbox_1.curselection.each { |x| puts x }
# End additional interface code.
end # list_scrl_entry1_ui
list_scrl_entry1_ui top
Tk.mainloop
1 Answer

Hidetoshi NAGAI

9/5/2003 7:39:00 AM

0