{
 "metadata": {
  "name": "",
  "signature": "sha256:f8a96fa9f559e8169a19de38e190920c7c87ad5a2ecae3d068468c11c8ecc55d"
 },
 "nbformat": 3,
 "nbformat_minor": 0,
 "worksheets": [
  {
   "cells": [
    {
     "cell_type": "heading",
     "level": 1,
     "metadata": {},
     "source": [
      "Chapter 10 : Programming visually"
     ]
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 10.1, Page No 171"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "import random\n",
      "nums = range(50)\n",
      "for i in range(1,50):\n",
      "    nums[i] = i\n",
      "for i in range(1,50):\n",
      "    j = random.randrange(1,49, 1)\n",
      "    k = nums[i]\n",
      "    nums[i] = nums[j]\n",
      "    nums[j] = k\n",
      "print \"Your six lucky numbers are: \"\n",
      "for i in range(1,7):\n",
      "    print nums[i],\" \",\n",
      "    \n"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [
      {
       "output_type": "stream",
       "stream": "stdout",
       "text": [
        "Your six lucky numbers are: \n",
        "30   5   38   20   7   29  \n"
       ]
      }
     ],
     "prompt_number": 5
    },
    {
     "cell_type": "heading",
     "level": 2,
     "metadata": {},
     "source": [
      "Example 10.2, Page No 173"
     ]
    },
    {
     "cell_type": "code",
     "collapsed": false,
     "input": [
      "from Tkinter import *\n",
      "from PIL import Image, ImageTk\n",
      "import random\n",
      "\n",
      "def getBtnClick():\n",
      "    nums = range(50)\n",
      "    for i in range(1,50):\n",
      "        nums[i] = i\n",
      "    for i in range(1,50):\n",
      "        j = random.randrange(1,49, 1)\n",
      "        k = nums[i]\n",
      "        nums[i] = nums[j]\n",
      "        nums[j] = k\n",
      "    label1.config(text = nums[0])\n",
      "    label2.config(text = nums[1])\n",
      "    label3.config(text = nums[2])\n",
      "    label4.config(text = nums[3])\n",
      "    label5.config(text = nums[4])\n",
      "    label6.config(text = nums[5])\n",
      "    getBtn.config(state=DISABLED)\n",
      "    resetBtn.config(state=NORMAL)\n",
      "def resetBtnClick():\n",
      "    label1.config(text = \"...\")\n",
      "    label2.config(text = \"...\")\n",
      "    label3.config(text = \"...\")\n",
      "    label4.config(text = \"...\")\n",
      "    label5.config(text = \"...\")\n",
      "    label6.config(text = \"...\")\n",
      "    resetBtn.config(state=DISABLED)\n",
      "    getBtn.config(state=NORMAL)\n",
      "root = Tk()\n",
      "root.title(\"Lotto number generator\")\n",
      "image = Image.open(\"lotto.gif\")\n",
      "photo = ImageTk.PhotoImage(image)\n",
      "label0 = Label(image=photo)\n",
      "label0.image = photo\n",
      "label0.grid(row=0,column=0,rowspan=2)\n",
      "\n",
      "label1 = Label(text=\"...\")\n",
      "label1.grid(row=0,column=1,padx=5,pady=5)\n",
      "label2 = Label(text=\"...\")\n",
      "label2.grid(row=0,column=2,padx=5,pady=5)\n",
      "label3 = Label(text=\"...\")\n",
      "label3.grid(row=0,column=3,padx=5,pady=5)\n",
      "label4 = Label(text=\"...\")\n",
      "label4.grid(row=0,column=4,padx=5,pady=5)\n",
      "label5 = Label(text=\"...\")\n",
      "label5.grid(row=0,column=5,padx=5,pady=5)\n",
      "label6 = Label(text=\"...\")\n",
      "label6.grid(row=0,column=6,padx=5,pady=5)\n",
      "\n",
      "getBtn = Button(text=\"Get My Lucky Numbers\",command=getBtnClick)\n",
      "getBtn.grid(row=1,column=2,columnspan=2)\n",
      "resetBtn = Button(text=\"Reset\",state=DISABLED,command=resetBtnClick)\n",
      "resetBtn.grid(row=1,column=4,columnspan=3)\n",
      "root.mainloop()"
     ],
     "language": "python",
     "metadata": {},
     "outputs": [],
     "prompt_number": 1
    }
   ],
   "metadata": {}
  }
 ]
}