<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Windows CentOS &#8211; Blog of Kliment Andreev &#8211; A place so I won&#039;t forget things</title>
	<atom:link href="https://blog.andreev.it/tag/windows-centos/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.andreev.it</link>
	<description></description>
	<lastBuildDate>Sat, 10 Oct 2020 13:18:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	
	<item>
		<title>FreeBSD, CentOS, Windows: Install Ruby/Tk on Windows 10, FreeBSD and CentOS. BONUS: quiz program in Ruby/Tk</title>
		<link>https://blog.andreev.it/2015/11/install-rubytk-on-windows-10-freebsd-and-centos/</link>
					<comments>https://blog.andreev.it/2015/11/install-rubytk-on-windows-10-freebsd-and-centos/#respond</comments>
		
		<dc:creator><![CDATA[Kliment Andreev]]></dc:creator>
		<pubDate>Fri, 27 Nov 2015 13:54:39 +0000</pubDate>
				<category><![CDATA[CentOS]]></category>
		<category><![CDATA[FreeBSD]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[freebsd]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Ruby/Tk]]></category>
		<category><![CDATA[Windows CentOS]]></category>
		<guid isPermaLink="false">http://blog.iandreev.com/?p=2076</guid>

					<description><![CDATA[In this post I&#8217;ll describe how to install Ruby and Tk. Tk is a&#8230;]]></description>
										<content:encoded><![CDATA[<div id="bsf_rt_marker"></div><p>In this post I&#8217;ll describe how to install Ruby and Tk. Tk is a GUI for Tcl (another script language) but it&#8217;s also used for Ruby. I recommend to read <a href="http://www.tkdocs.com/index.html" target="_blank" rel="noopener noreferrer">this </a>tutorial first if this is the first time you are dealing with Tk. You&#8217;ll need some basic understanding of geometry (layout) managers, such as pack, grid and place. </p>
<h1>Windows 7 and Windows 10</h1>
<p>The installation for Windows is the same for Windows 7 and Windows 10. It&#8217;s very straightforward. Go to http://rubyinstaller.org/downloads/ and download Ruby 2.1.7 (32-bit or 64-bit). When you start the install, make sure you select the Tcl/Tk support and add Ruby to your PATH.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2015/11/P059-01.png"><img fetchpriority="high" decoding="async" src="https://blog.andreev.it/wp-content/uploads/2015/11/P059-01.png" alt="" width="513" height="399" class="aligncenter size-full wp-image-7377" srcset="https://blog.andreev.it/wp-content/uploads/2015/11/P059-01.png 513w, https://blog.andreev.it/wp-content/uploads/2015/11/P059-01-300x233.png 300w" sizes="(max-width: 513px) 100vw, 513px" /></a><br />
Once installed, open a command prompt and type <strong>irb</strong>. When you see the interactive Ruby prompt, type <strong>require &#8216;tk&#8217;</strong> and hit Enter. You should see True as result.<br />
<a href="https://blog.andreev.it/wp-content/uploads/2015/11/P059-02.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2015/11/P059-02.png" alt="" width="329" height="154" class="aligncenter size-full wp-image-7378" srcset="https://blog.andreev.it/wp-content/uploads/2015/11/P059-02.png 329w, https://blog.andreev.it/wp-content/uploads/2015/11/P059-02-300x140.png 300w" sizes="(max-width: 329px) 100vw, 329px" /></a></p>
<h1>FreeBSD 10</h1>
<p>Tcl, Tk and Ruby are standard in the ports tree, but the Ruby install doesn&#8217;t allow the configuration for Tk. Earlier, there was a port called ruby-tk, but it&#8217;s depreciated since Ruby 1.9. First, install Tcl and Tk.</p>
<pre class="brush: bash; title: ; notranslate">
pkg install tcl85 tk85
</pre>
<p>Download the tarball from Ruby&#8217;s website, unpack it and install it. </p>
<pre class="brush: bash; title: ; notranslate">
pkg install tcl85 tk85
wget https://cache.ruby-lang.org/pub/ruby/2.1/ruby-2.1.7.tar.gz
tar xvf ruby-2.1.7.tar.gz
rm ruby-2.1.7.tar.gz
cd ruby-2.1.7.tar.gz
./configure --without-ActiveTcl --with-tclConfig-dir=/usr/local/lib/tcl8.5 --with-tkConfig-dir=/usr/local/lib/tk8.5 --with-tcl-include=/usr/local/include/tcl8.5 --with-tk-include=/usr/local/include/tk8.5 --with-tcl-lib=/usr/local/lib --with-tk-lib=/usr/local/lib
make
make install
</pre>
<p>Do the same test, type <strong>irb </strong>and then type <strong>require &#8216;tk&#8217;</strong>. If you are running the test from a ssh session, you&#8217;ll receive an error that there is no display. This is fine, Ruby/Tk can&#8217;t initialize the graphic environment. You should test it from the GUI of your choice (Gnome, KDE, mate, xfce&#8230;)<br />
<a href="https://blog.andreev.it/wp-content/uploads/2015/11/P059-03.png"><img decoding="async" src="https://blog.andreev.it/wp-content/uploads/2015/11/P059-03.png" alt="" width="756" height="134" class="aligncenter size-full wp-image-7379" srcset="https://blog.andreev.it/wp-content/uploads/2015/11/P059-03.png 756w, https://blog.andreev.it/wp-content/uploads/2015/11/P059-03-300x53.png 300w, https://blog.andreev.it/wp-content/uploads/2015/11/P059-03-585x104.png 585w" sizes="(max-width: 756px) 100vw, 756px" /></a></p>
<h1>CentOS 7</h1>
<p>CentOS 7 install is also very simple. Install Ruby/Tk with:</p>
<pre class="brush: bash; title: ; notranslate">
yum install ruby ruby-tcltk
</pre>
<p>Same as the previous installs, type <strong>irb </strong>and then type <strong>require &#8216;tk&#8217;</strong>.</p>
<h1>Example</h1>
<p>I was playing a couple of days with Ruby/Tk and made a simple quiz program. You can get it from <a href="https://www.github.com/klimenta/GemQuiz" target="_blank" rel="noopener noreferrer">https://www.github.com/klimenta/GemQuiz</a> or:</p>
<pre class="brush: bash; title: ; notranslate">
git clone https://www.github.com/klimenta/GemQuiz
</pre>
<p>The source code is also below and the instructions on how to make your own quiz. I am using the grid geometry manager. The source is not well documented and there are too many global variables, but it&#8217;s more an example of Tk rather than proper Ruby programming.</p>
<pre class="brush: ruby; collapse: true; light: false; title: ; toolbar: true; notranslate">
#######################################################################################################################
#### The quiz has to be in the following format, no blank lines are allowed                                        ####
####                                                                                                               ####
#### Question number                                                                                               ####
#### Question text (one continuous line, the program takes care of the wrapping)                                   ####
#### Four possible answers, each line starts with A., B., C. and D.                                                ####
#### Answer(s) line that starts with the words &quot;Answer: &quot; (no quotes) and the correct answer                       ####
####      The program takes care of single/multiple choice answer widgets                                          ####
#######################################################################################################################
#### e.g.                                                                                                          ####
#######################################################################################################################
#### Q1.                                                                                                           ####
#### Leveraged loans are loans provided to companies that already have a significant amount of outstanding debt.   ####
#### As a banker, how might you compare a leveraged loan to other loans in your portfolio?                         ####
#### A. Higher risk to the lender but less costly to the borrower.                                                 ####
#### B. Lower risk to the lender and less costly to the borrower.                                                  ####
#### C. Lower risk to the lender but more costly to the borrower.                                                  ####
#### D. Higher risk to the lender and more costly to the borrower.                                                 ####
#### Answer: D                                                                                                     ####
#######################################################################################################################
#### This example will create a quiz with 4 radio buttons. If the answer line was Answer: B,C                      ####
#### then the program will show four check buttons instead.                                                        ####
#### NOTE: The question in this example is two lines. In the file, it should be one continuous line                ####                                                      ####
#######################################################################################################################

require 'tk'
require 'tkextlib/tile'

# Creates the root (parent) windows, 800 x 600, not resizable
$root = TkRoot.new
$root.minsize(width = 800, height = 600)
$root.maxsize(width = 800, height = 600)
$root.resizable(false, false)

TkOption.add '*tearOff', 0

# Creates the menu with two options (open and exit)
menuBar = TkMenu.new($root)
$root&#x5B;'menu'] = menuBar
menuFile = TkMenu.new(menuBar)
menuBar.add :cascade, :menu =&gt; menuFile, :label =&gt; 'File'
menuFile.add :command, :label =&gt; 'Open...', :command =&gt; proc{ openFile }
menuFile.add :command, :label =&gt; 'Exit', :command =&gt; proc{ exitProgram }

# Templates for the label's size and color
Tk::Tile::Style.configure('Question.TLabel', {&quot;font&quot; =&gt; &quot;helvetica 14&quot;, &quot;foreground&quot; =&gt; &quot;black&quot;})
Tk::Tile::Style.configure('QuestionNumber.TLabel', {&quot;font&quot; =&gt; &quot;helvetica 20&quot;, &quot;foreground&quot; =&gt; &quot;red&quot;})
Tk::Tile::Style.configure('Correct.TLabel', {&quot;font&quot; =&gt; &quot;helvetica 14&quot;, &quot;foreground&quot; =&gt; &quot;darkgreen&quot;})
Tk::Tile::Style.configure('Answer.TLabel', {&quot;font&quot; =&gt; &quot;helvetica 14&quot;, &quot;foreground&quot; =&gt; &quot;blue&quot;})
Tk::Tile::Style.configure('Stats.TLabel', {&quot;font&quot; =&gt; &quot;helvetica 10&quot;, &quot;foreground&quot; =&gt; &quot;black&quot;})

# Variables
$arrQuestionLines = Array.new # All the question lines are stored here, e.g. Q1, Q2
$arrAnswerA = Array.new # All the possible answers that show up as answer A.
$arrAnswerB = Array.new # All the possible answers that show up as answer B.
$arrAnswerC = Array.new # All the possible answers that show up as answer C.
$arrAnswerD = Array.new # All the possible answers that show up as answer D.
$arrQuestions = Array.new # All the questions are stored in this array
$arrCorrectAnswers = Array.new # These are the correct answers for the questions
$arrUserAnswers = Array.new # These are the answers that the users picked up

$intQuestionOnScreen = 0 # The current question on the screen
$intTotalQuestions = 1 # Total number of questions

# Opens up the quiz file and loads all the content into an array
def openFile
  arrQuizContents = Array.new
  $filename = Tk::getOpenFile
  begin
    f = File.open($filename) or die &quot;Unable to open file...&quot;
  rescue # In case the users hits cancel or ESC, return to the menu
    return
  end
  arrQuizContents = &#x5B;]
  f.each_line {|strLine|
    arrQuizContents.push strLine # Puts the file in one array
  }
  f.close
  ParseFile(arrQuizContents)
  $intQuestionOnScreen = 1
  StartQuiz()
end

# Parses the contents array and gets question number lines, questions, possible answers and correct answers
def ParseFile(arr)
  arr.each do |strLine|
    if strLine.match(/^&#x5B;Qq]&#x5B;0-9]/)
      $arrQuestionLines.push strLine
    elsif strLine.match(/^&#x5B;Aa]\./)
      $arrAnswerA.push strLine
    elsif strLine.match(/^&#x5B;Bb]\./)
      $arrAnswerB.push strLine
    elsif strLine.match(/^&#x5B;Cc]\./)
      $arrAnswerC.push strLine
    elsif strLine.match(/^&#x5B;Dd]\./)
      $arrAnswerD.push strLine
    elsif strLine.match(/^Answer:/)
      $arrCorrectAnswers.push ((strLine.sub(&quot;Answer:&quot;, &quot;&quot;)).gsub(&quot; &quot;,&quot;&quot;)).gsub(&quot;,&quot;,&quot;&quot;).gsub(/\n/,&quot;&quot;)
    else
      $arrQuestions.push strLine
    end
  end
  $intTotalQuestions = $arrQuestionLines.length
end

# Initializes all the widgets and arranges them on the screen
# Frame widgets start with frm
# label widgets start with lbl
# button widgets start with btn
# grid_propagate(false) means that the frame is absolute.
# The size (height, width) always stay the same
def StartQuiz()
  frmQuestion = Tk::Tile::Frame.new($root) {width 760; height 175}
  frmQuestion.grid :column =&gt; 1, :row =&gt; 0, :columnspan =&gt; 4
  frmQuestion.grid_propagate(false)
  frmAnswerA = Tk::Tile::Frame.new($root) {width 760; height 90}
  frmAnswerA.grid :column =&gt; 1, :row =&gt; 1, :columnspan =&gt; 4
  frmAnswerA.grid_propagate(false)
  frmAnswerB = Tk::Tile::Frame.new($root) {width 760; height 90}
  frmAnswerB.grid :column =&gt; 1, :row =&gt; 2, :columnspan =&gt; 4
  frmAnswerB.grid_propagate(false)
  frmAnswerC = Tk::Tile::Frame.new($root) {width 760; height 90}
  frmAnswerC.grid :column =&gt; 1, :row =&gt; 3, :columnspan =&gt; 4
  frmAnswerC.grid_propagate(false)
  frmAnswerD = Tk::Tile::Frame.new($root) {width 760; height 90}
  frmAnswerD.grid :column =&gt; 1, :row =&gt; 4, :columnspan =&gt; 4
  frmAnswerD.grid_propagate(false)
  $frmChoiceA = Tk::Tile::Frame.new($root) {width 40; height 90}
  $frmChoiceA.grid :column =&gt; 0, :row =&gt; 1
  $frmChoiceA.grid_propagate(false)
  $frmChoiceB = Tk::Tile::Frame.new($root) {width 40; height 90}
  $frmChoiceB.grid :column =&gt; 0, :row =&gt; 2
  $frmChoiceB.grid_propagate(false)
  $frmChoiceC = Tk::Tile::Frame.new($root) {width 40; height 90}
  $frmChoiceC.grid :column =&gt; 0, :row =&gt; 3
  $frmChoiceC.grid_propagate(false)
  $frmChoiceD = Tk::Tile::Frame.new($root) {width 40; height 90}
  $frmChoiceD.grid :column =&gt; 0, :row =&gt; 4
  $frmChoiceD.grid_propagate(false)
  frmNothing = Tk::Tile::Frame.new($root) {width 40; height 65}
  frmNothing.grid :column =&gt; 0, :row =&gt; 5, :rowspan =&gt; 2
  frmNothing.grid_propagate(false)
  frmStats = Tk::Tile::Frame.new($root) {width 760; height 30}
  frmStats.grid :column =&gt; 1, :row =&gt; 6, :columnspan =&gt; 4
  frmStats.grid_propagate(false)
  frmNumber = Tk::Tile::Frame.new($root) {width 40; height 175}
  frmNumber.grid :column =&gt; 0, :row =&gt; 0
  frmNumber.grid_propagate(false)
  frmbtnAnswer = Tk::Tile::Frame.new($root) {width 190; height 35}
  frmbtnAnswer.grid :column =&gt; 1, :row =&gt; 5
  frmbtnAnswer.grid_propagate(false)
  frmbtnPrev = Tk::Tile::Frame.new($root) {width 190; height 35}
  frmbtnPrev.grid :column =&gt; 2, :row =&gt; 5
  frmbtnPrev.grid_propagate(false)
  frmbtnNext = Tk::Tile::Frame.new($root) {width 190; height 35}
  frmbtnNext.grid :column =&gt; 3, :row =&gt; 5
  frmbtnNext.grid_propagate(false)
  frmbtnFinish = Tk::Tile::Frame.new($root) {width 190; height 35}
  frmbtnFinish.grid :column =&gt; 4, :row =&gt; 5
  frmbtnFinish.grid_propagate(false)

  btnAnswer = Tk::Tile::Button.new(frmbtnAnswer) {text &quot;Answer&quot;; command {answerQuestion()}}
  $btnPrev = Tk::Tile::Button.new(frmbtnPrev) {text &quot;&lt; Prev&quot;; command {prevQuestion()}}
  $btnPrev.state = 'disabled'
  $btnNext = Tk::Tile::Button.new(frmbtnNext) {text &quot;Next &gt;&quot;; command {nextQuestion()}}
  btnFinish = Tk::Tile::Button.new(frmbtnFinish) {text &quot;Finish&quot;; command {finishQuestion()}}

  $lblQuestionNumber  = Tk::Tile::Label.new(frmNumber) {text &quot;&quot;}
  $lblQuestionNumber&#x5B;'style'] = &quot;QuestionNumber.TLabel&quot;

  $lblStats = Tk::Tile::Label.new(frmStats) {text &quot;Program by Kliment ANDREEV - 2015&quot;}
  $lblStats&#x5B;'style'] = &quot;Stats.TLabel&quot;
  $lblStats.grid :column =&gt;0 , :row =&gt; 0
  $lblStats.text = $filename + &quot; | Program by Kliment Andreev - 2015&quot;

  $lblQuestion = Tk::Tile::Label.new(frmQuestion) {text &quot;&quot; ;wraplength 755 }
  $lblQuestion&#x5B;'style'] = &quot;Question.TLabel&quot;

  $lblAnswerA = Tk::Tile::Label.new(frmAnswerA) {
    text &quot;&quot;
    wraplength 755
  }.grid( :column =&gt; 0, :row =&gt; 0, :sticky =&gt; 'w')
  $lblAnswerA&#x5B;'style'] = &quot;Answer.TLabel&quot;

  $lblAnswerB = Tk::Tile::Label.new(frmAnswerB) {
    text &quot;&quot;
    wraplength 755
  }.grid( :column =&gt; 0, :row =&gt; 1, :sticky =&gt; 'w')
  $lblAnswerB&#x5B;'style'] = &quot;Answer.TLabel&quot;

  $lblAnswerC = Tk::Tile::Label.new(frmAnswerC) {
    text &quot;&quot;
    wraplength 755
  }.grid( :column =&gt; 0, :row =&gt; 2, :sticky =&gt; 'w')
  $lblAnswerC&#x5B;'style'] = &quot;Answer.TLabel&quot;

  $lblAnswerD = Tk::Tile::Label.new(frmAnswerD) {
    text &quot;&quot;
    wraplength 755
  }.grid( :column =&gt; 0, :row =&gt; 3, :sticky =&gt; 'w')
  $lblAnswerD&#x5B;'style'] = &quot;Answer.TLabel&quot;

  btnAnswer.grid :column =&gt; 0, :row =&gt; 0
  $btnPrev.grid :column =&gt; 0, :row =&gt; 0
  $btnNext.grid :column =&gt; 0, :row =&gt; 0
  btnFinish.grid :column =&gt; 0, :row =&gt; 0

  printQuestionOnScreen()
  printAnswersOnScreen()
  printChoicesOnScreen()
end

# Prints the question and the question number on the screen
def printQuestionOnScreen()
  $lblQuestionNumber.grid :column =&gt; 0, :row =&gt; 0
  $lblQuestionNumber&#x5B;'text'] = $intQuestionOnScreen.to_s + &quot;.&quot;
  $lblQuestion.grid :column =&gt; 1, :row =&gt; 0
  $lblQuestion&#x5B;'text'] = $arrQuestions&#x5B;$intQuestionOnScreen - 1]
end

# Prints all four possible answers on the screen
def printAnswersOnScreen()
  $lblAnswerA&#x5B;'text'] = $arrAnswerA&#x5B;$intQuestionOnScreen - 1]
  $lblAnswerB&#x5B;'text'] = $arrAnswerB&#x5B;$intQuestionOnScreen - 1]
  $lblAnswerC&#x5B;'text'] = $arrAnswerC&#x5B;$intQuestionOnScreen - 1]
  $lblAnswerD&#x5B;'text'] = $arrAnswerD&#x5B;$intQuestionOnScreen - 1]
end

# Destroys the choice widgets when the user chooses previous or next question
def destroyChoicesOnScreen()
  if $strAnswer.length == 1
    $radioA.destroy
    $radioB.destroy
    $radioC.destroy
    $radioD.destroy
  else
    $checkA.destroy
    $checkB.destroy
    $checkC.destroy
    $checkD.destroy
  end
end

# Prints the radio buttons or check buttons (choices) for the answers
def printChoicesOnScreen()
  $strAnswer = ($arrCorrectAnswers&#x5B;$intQuestionOnScreen -  1].strip)
  # Based on the number of correct answers, the program decides to use radio or check buttons
  if $strAnswer.length == 1
    $radioChoice = TkVariable.new
    $radioA = Tk::Tile::RadioButton.new($frmChoiceA) {text ''; variable $radioChoice; value 'A'; command {yourAnswer}}
    $radioB = Tk::Tile::RadioButton.new($frmChoiceB) {text ''; variable $radioChoice; value 'B'; command {yourAnswer}}
    $radioC = Tk::Tile::RadioButton.new($frmChoiceC) {text ''; variable $radioChoice; value 'C'; command {yourAnswer}}
    $radioD = Tk::Tile::RadioButton.new($frmChoiceD) {text ''; variable $radioChoice; value 'D'; command {yourAnswer}}
    $radioA.grid :column =&gt; 0, :row =&gt; 0
    $radioB.grid :column =&gt; 0, :row =&gt; 0
    $radioC.grid :column =&gt; 0, :row =&gt; 0
    $radioD.grid :column =&gt; 0, :row =&gt; 0
  else
    $option_one = TkVariable.new( 0 )
    $checkA = Tk::Tile::CheckButton.new($frmChoiceA) {text &quot;&quot;; variable $option_one; onvalue 'A'; command {yourAnswer}}
    $option_two = TkVariable.new( 0 )
    $checkB = Tk::Tile::CheckButton.new($frmChoiceB) {text &quot;&quot;; variable $option_two; onvalue 'B'; command {yourAnswer}}
    $option_three = TkVariable.new( 0 )
    $checkC = Tk::Tile::CheckButton.new($frmChoiceC) {text &quot;&quot;; variable $option_three; onvalue 'C'; command {yourAnswer}}
    $option_four = TkVariable.new( 0 )
    $checkD = Tk::Tile::CheckButton.new($frmChoiceD) {text &quot;&quot;; variable $option_four; onvalue 'D'; command {yourAnswer}}
    $checkA.grid :column =&gt; 0, :row =&gt; 0
    $checkB.grid :column =&gt; 0, :row =&gt; 0
    $checkC.grid :column =&gt; 0, :row =&gt; 0
    $checkD.grid :column =&gt; 0, :row =&gt; 0
  end
end

# When user clicks the button for the next question
def nextQuestion()
  return if $intQuestionOnScreen == 0 || $intQuestionOnScreen == $intTotalQuestions
  $intQuestionOnScreen += 1
  if $intQuestionOnScreen == $intTotalQuestions
    $btnNext.state = 'disabled'
  end
  destroyChoicesOnScreen()
  resetAnswerLabelColors()
  printQuestionOnScreen()
  printAnswersOnScreen()
  printChoicesOnScreen()
  printUsersChoiceOnScreen()
  $btnPrev.state = 'enabled'
end

# Resets answers to the default look
def resetAnswerLabelColors()
  $lblAnswerA&#x5B;'style'] = &quot;Answer.TLabel&quot;
  $lblAnswerB&#x5B;'style'] = &quot;Answer.TLabel&quot;
  $lblAnswerC&#x5B;'style'] = &quot;Answer.TLabel&quot;
  $lblAnswerD&#x5B;'style'] = &quot;Answer.TLabel&quot;
end

# When user clicks the button for the previous question
def prevQuestion()
  return if $intQuestionOnScreen == 0 || $intQuestionOnScreen == 1
  $btnNext.state = 'enabled'
  $intQuestionOnScreen -= 1
  if $intQuestionOnScreen == 1
    $btnPrev.state = 'disabled'
  end
  destroyChoicesOnScreen()
  resetAnswerLabelColors()
  printQuestionOnScreen()
  printAnswersOnScreen()
  printChoicesOnScreen()
  printUsersChoiceOnScreen()
end

# Prints whatever the user selected when the previous or next question is displayed
def printUsersChoiceOnScreen()
  $strAnswer = ($arrCorrectAnswers&#x5B;$intQuestionOnScreen -  1].strip)
  if $strAnswer.length == 1
    case $arrUserAnswers&#x5B;$intQuestionOnScreen - 1]
      when &quot;A&quot;
        $radioA.invoke()
      when &quot;B&quot;
        $radioB.invoke()
      when &quot;C&quot;
        $radioC.invoke()
      when &quot;D&quot;
        $radioD.invoke()
    end
  else
    case $arrUserAnswers&#x5B;$intQuestionOnScreen - 1]
      when &quot;A&quot;
        checkInvoke(true, false, false, false)
      when &quot;B&quot;
        checkInvoke(false, true, false, false)
      when &quot;C&quot;
        checkInvoke(false, false, true, false)
      when &quot;D&quot;
        checkInvoke(false, false, false, true)
      when &quot;AB&quot;
        checkInvoke(true, true, false, false)
      when &quot;AC&quot;
        checkInvoke(true, false, true, false)
      when &quot;AD&quot;
        checkInvoke(true, false, false, true)
      when &quot;BC&quot;
        checkInvoke(false, true, true, false)
      when &quot;BD&quot;
        checkInvoke(false, true, false, true)
      when &quot;CD&quot;
        checkInvoke(false, false, true, true)
      when &quot;ABC&quot;
        checkInvoke(true, true, true, false)
      when &quot;ABD&quot;
        checkInvoke(true, true, false, true)
      when &quot;ACD&quot;
        checkInvoke(true, false, true, true)
      when &quot;BCD&quot;
        checkInvoke(false, true, true, true)
      when &quot;ABCD&quot;
        checkInvoke(true, true, true, true)
    end
  end
end

def selectAnswerA
  $checkA.invoke()
end

def selectAnswerB
  $checkB.invoke()
end

def selectAnswerC
  $checkC.invoke()
end

def selectAnswerD
  $checkD.invoke()
end

def checkInvoke(bA, bB, bC, bD)
  arr = &#x5B;method(:selectAnswerA), method(:selectAnswerB), method(:selectAnswerC), method(:selectAnswerD)]
  arr&#x5B;0].call if bA
  arr&#x5B;1].call if bB
  arr&#x5B;2].call if bC
  arr&#x5B;3].call if bD
end

# Prints the correct answer on the screen when user clicks on the Answer button
def answerQuestion()
  return if $intQuestionOnScreen == 0
  case $strAnswer
    when &quot;A&quot;
      $lblAnswerA&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;B&quot;
      $lblAnswerB&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;C&quot;
      $lblAnswerC&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;D&quot;
      $lblAnswerD&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;AB&quot;
      $lblAnswerA&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerB&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;AC&quot;
      $lblAnswerA&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerC&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;AD&quot;
      $lblAnswerA&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerD&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;BC&quot;
      $lblAnswerB&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerC&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;BD&quot;
      $lblAnswerB&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerD&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;CD&quot;
      $lblAnswerC&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerD&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;ABC&quot;
      $lblAnswerA&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerB&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerC&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;ABD&quot;
      $lblAnswerA&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerB&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerC&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;ACD&quot;
      $lblAnswerA&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerC&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerD&#x5B;'style'] = &quot;Correct.TLabel&quot;
    when &quot;BCD&quot;
      $lblAnswerB&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerC&#x5B;'style'] = &quot;Correct.TLabel&quot;
      $lblAnswerD&#x5B;'style'] = &quot;Correct.TLabel&quot;
    else
      $lblAnswerA&#x5B;'style'] =&quot;Correct.TLabel&quot;
      $lblAnswerB&#x5B;'style'] =&quot;Correct.TLabel&quot;
      $lblAnswerC&#x5B;'style'] =&quot;Correct.TLabel&quot;
      $lblAnswerD&#x5B;'style'] =&quot;Correct.TLabel&quot;
  end
end

# Finishes the quiz when the user clicks on the Finish button and displays the stats
def finishQuestion()
  # Compares the arrays of correct answers and user's selected answers
  # and creates another array with correct (true) answers
  arrTrueAnswers = $arrUserAnswers.zip($arrCorrectAnswers).map { |x, y| x == y}
  x = arrTrueAnswers.count(true)
  msgBox = Tk.messageBox(
      'type'    =&gt; &quot;ok&quot;,
      'icon'    =&gt; &quot;info&quot;,
      'title'   =&gt; &quot;GemQuiz - Stats&quot;,
      'message' =&gt; &quot;You have &quot; + x.to_s + &quot; correct answers out of &quot; + $intTotalQuestions.to_s + &quot;.
                    That's &quot; + ((x.to_f / $intTotalQuestions.to_f) * 100).round(2).to_s + &quot;%.&quot;)
end

# Updates the array with the answer that the user selected
def yourAnswer()
  if $strAnswer.length == 1
    $arrUserAnswers&#x5B;$intQuestionOnScreen - 1, 1] = $radioChoice
  else
    $arrUserAnswers&#x5B;$intQuestionOnScreen - 1] = ($option_one.to_s + $option_two.to_s + $option_three.to_s + $option_four.to_s).gsub(&quot;0&quot;, &quot;&quot;)
  end
end

# Exits the program if selected from the menu
def exitProgram
  exit(0)
end

Tk.mainloop
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.andreev.it/2015/11/install-rubytk-on-windows-10-freebsd-and-centos/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
