Newbie having trouble with SpecTcl, TkListbox and TkScrollbar

E

Ed Baker

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
 
H

Hidetoshi NAGAI

Hi,

From: (e-mail address removed) (Ed Baker)
Subject: Newbie having trouble with SpecTcl, TkListbox and TkScrollbar
Date: Fri, 5 Sep 2003 15:49:00 +0900
Message-ID: said:
Everything works 'visually'. But, I can't seem to figure out the index
value returned from the list box.

Although I don't know what you want, could the following patch help you?

--- aaa-orig.rb 2003-09-05 16:24:50.000000000 +0900
+++ aaa.rb 2003-09-05 16:23:39.000000000 +0900
@@ -48,11 +48,10 @@
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 }
+ listbox_1.bind('ButtonRelease-1', proc{
+ listbox_1.curselection.collect {|x| p [x, listbox_1.get(x)] }
+ @zzentry.value = listbox_1.get(listbox_1.curselection[0])
+ })
# End additional interface code.
end # list_scrl_entry1_ui
list_scrl_entry1_ui top
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top