Michael DeHaan
11/4/2004 6:13:00 PM
I'd consider hiding the root window after the input is provided, so
that it stays around but you can't see it. Tk can definitely support
multiple windows, add as many as you like.
I've only done Perl/Tk to this point, so I can't give you the
ruby-specific syntax...
--MPD
On Fri, 5 Nov 2004 02:09:08 +0900, Kujawa, Greg
<greg.kujawa@diamondcellar.com> wrote:
> I am new to Ruby and trying to create a basic application using Tk.
> Unfortunately I'm also new to this as well :-)
>
> The application is for a survey. I have created an initial window where the
> survey taker signs in. They select their name from a TkListbox object. When
> they click on a TkButton object the sign in window exits and I record the
> appropriate current selection of the listbox object.
>
> My question is how would I go about creating a new window for taking survey
> itself and still keep the saved selection of the listbox object? Is Tk
> intended more for a single windowed application? I read about multi-tk and
> was wondering if this might be the way to go. I want to create a new window
> for the survey, record the takers responses and then clear their name off
> the sign in list after they have completed things. That's why I want to
> retain the sign in's selection for the lifetime of the application.
>
> Here is my current code for the survey sign in below. Any pointers would be
> appreciated!
>
> require 'dbi'
> require 'tk'
>
> # connect to the SQL data source
> dsn= 'DBI:ADO:Provider=SQLOLEDB;Data Source=mobile_tech;Initial
> Catalog=CoreVals;Persist Security Info=False;Trusted_Connection=Yes;'
>
> DBI.connect(dsn) do |dbh|
>
> # select all employees that haven't completed the survey
> dbh.execute("SELECT First+' '+MI+' '+Last FROM TblEmployee where Done=0
> order by Last, First") do |sth|
>
> # populate the returned recordset into an array
> $employee = sth.fetch_all
> end
> end
>
> # create a new window for the sign in using Tk
> @root = TkRoot.new() {title 'Core Values Survey'}
>
> listViewFrm = TkFrame.new(@root).pack(
> 'side'=>'left',
> 'padx'=>10,
> 'pady'=>10,
> 'fill'=>'both')
>
> # Create a scrollbar for the employee listbox
> scrollbar = TkScrollbar.new(listViewFrm).pack(
> 'side'=>'right',
> 'fill'=>'y')
>
> # Create the listbox to hold all of the employees
> $empListbox = TkListbox.new(listViewFrm) {
> width 25
> }.pack(
> 'fill'=>'y',
> 'expand'=>'true')
>
> # Link the listbox to scrollbar
> $empListbox.yscrollbar(scrollbar)
>
> # Populate the listbox control with the employee recordset
> $employee.each { |emp|
> $empListbox.insert('end', emp)
> }
>
> # Add the sign in button
> button = TkButton.new(@root) { text "Sign me in!"
> command proc {
> indexstr = $empListbox.curselection.to_s;
> indexnum = indexstr.to_i;
> $taker=$employee[indexnum].to_s;
> p $taker;
> exit
> }
> }
> button.pack("side"=>"right")
>
> Tk.mainloop
>
>