K
Kujawa, Greg
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:ADOrovider=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
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:ADOrovider=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