diff options
author | Jovina Dsouza | 2014-06-18 12:43:07 +0530 |
---|---|---|
committer | Jovina Dsouza | 2014-06-18 12:43:07 +0530 |
commit | 206d0358703aa05d5d7315900fe1d054c2817ddc (patch) | |
tree | f2403e29f3aded0caf7a2434ea50dd507f6545e2 /Let_us_C/chapter-18.ipynb | |
parent | c6f0d6aeb95beaf41e4b679e78bb42c4ffe45a40 (diff) | |
download | Python-Textbook-Companions-206d0358703aa05d5d7315900fe1d054c2817ddc.tar.gz Python-Textbook-Companions-206d0358703aa05d5d7315900fe1d054c2817ddc.tar.bz2 Python-Textbook-Companions-206d0358703aa05d5d7315900fe1d054c2817ddc.zip |
adding book
Diffstat (limited to 'Let_us_C/chapter-18.ipynb')
-rw-r--r-- | Let_us_C/chapter-18.ipynb | 261 |
1 files changed, 261 insertions, 0 deletions
diff --git a/Let_us_C/chapter-18.ipynb b/Let_us_C/chapter-18.ipynb new file mode 100644 index 00000000..7a30b0b6 --- /dev/null +++ b/Let_us_C/chapter-18.ipynb @@ -0,0 +1,261 @@ +{
+ "metadata": {
+ "name": "chapter-18.ipynb"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h1>Chapter 18: Graphics Under Windows<h1>"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Hello Windows, Page number: 582<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to display a message \u201cHello Windows\u201d in different fonts'''\n",
+ "\n",
+ "from tkinter import *\n",
+ "\n",
+ "\n",
+ "class Example(Frame):\n",
+ " def __init__(self, parent):\n",
+ " Frame.__init__(self, parent)\n",
+ "\n",
+ " self.display = Canvas(self, width=700, height=200)\n",
+ " self.display.pack(side=\"top\", fill=\"both\", expand=True)\n",
+ " self.display.create_text(10, 10, fill = \"blue\",text = \"Hello Windows\", font=\"Arial 20 italic\",\n",
+ " anchor=\"nw\")\n",
+ " self.display.create_text(10, 50, fill = \"blue\",text = \"Hello Windows\", font=\"TimesNewRoman 30 italic\",\n",
+ " anchor=\"nw\")\n",
+ " self.display.create_text(10, 100, fill = \"blue\",text = \"Hello Windows\", font=\"ComicSansMS 40 italic\",\n",
+ " anchor=\"nw\")\n",
+ "\n",
+ "if __name__ == \"__main__\":\n",
+ " root = Tk()\n",
+ " root.title(\"Text\")\n",
+ " Frame = Example(parent=root)\n",
+ " Frame.pack(side=\"top\", fill=\"both\", expand=True)\n",
+ " root.mainloop()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Drawing Shapes, Page number: 587<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program that displays different shapes in a window'''\n",
+ "\n",
+ "from tkinter import *\n",
+ "\n",
+ "\n",
+ "top = Tk()\n",
+ "top.title(\"Shapes\")\n",
+ "C = Canvas(top, height=500, width=500)\n",
+ "rcoor = 10,20,200,100\n",
+ "rect = C.create_rectangle(rcoor,fill=\"blue\")#rectangle\n",
+ "ecoor = 10,280,200,380\n",
+ "ellipse = C.create_oval(ecoor,fill = \"blue\")#ellipse\n",
+ "picoor = 250,0,350,100\n",
+ "pie = C.create_arc(picoor, start=300, extent=100, fill=\"blue\")#pie\n",
+ "pocoor = 250, 150, 250, 300, 300, 350, 400, 300, 320, 190\n",
+ "polygon = C.create_polygon(pocoor,fill=\"blue\")#polygon\n",
+ "#roundedrectangle\n",
+ "c1= C.create_arc(155,115,195,150,start=320, extent=80, fill=\"blue\",outline=\"blue\")\n",
+ "c2= C.create_arc(155,208,195,243,start=320, extent=80, fill=\"blue\",outline=\"blue\")\n",
+ "c3= C.create_arc(25,118,60,153,start=100, extent=150, fill=\"blue\",outline=\"blue\")\n",
+ "c4= C.create_arc(25,207,60,242,start=100, extent=150, fill=\"blue\",outline=\"blue\")\n",
+ "roundrect = C.create_rectangle(30,120,190,240,fill=\"blue\",outline=\"blue\")\n",
+ "C.pack()\n",
+ "top.mainloop()"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Pen Styles, Page number: 590<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to create pens of different style, color and\n",
+ "thickness to draw'''\n",
+ "\n",
+ "from tkinter import *\n",
+ "\n",
+ "\n",
+ "top = Tk()\n",
+ "top.title(\"Pen styles\")\n",
+ "C = Canvas(top, height=100, width=500)\n",
+ "l1 = C.create_line(0,10,500,10,fill=\"red\",dash=(5)) #dashed line\n",
+ "l2 = C.create_line(0,30,500,30,fill=\"red\",dash=(1)) #dotted line\n",
+ "l3 = C.create_line(0,50,500,50,fill=\"red\",dash=(5,1,1,1)) #dash dot\n",
+ "l4 = C.create_line(0,70,500,70,fill=\"red\",dash=(5,1,1,1,1)) #dash dot dot\n",
+ "l5 = C.create_line(0,90,500,90,fill=\"red\",width=4) #solid line\n",
+ "C.pack()\n",
+ "top.mainloop()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Types of Brushes, Page number: 592<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "import sys\n",
+ "from PyQt4 import QtGui, QtCore\n",
+ "\n",
+ "\n",
+ "class Example(QtGui.QWidget):\n",
+ " \n",
+ " def __init__(self):\n",
+ " super(Example, self).__init__()\n",
+ " \n",
+ " self.initUI()\n",
+ " \n",
+ " def initUI(self): \n",
+ "\n",
+ " self.setGeometry(300, 300, 355, 280)\n",
+ " self.setWindowTitle('Brush Styles')\n",
+ " self.show()\n",
+ "\n",
+ " def paintEvent(self, e):\n",
+ "\n",
+ " qp = QtGui.QPainter()\n",
+ " qp.begin(self)\n",
+ " self.drawBrushes(qp)\n",
+ " qp.end()\n",
+ " \n",
+ " def drawBrushes(self, qp):\n",
+ " \n",
+ " brush = QtGui.QBrush(QtCore.Qt.SolidPattern)\n",
+ " qp.setBrush(brush)\n",
+ " qp.drawRect(10, 15, 90, 60)\n",
+ "\n",
+ " brush.setStyle(QtCore.Qt.CrossPattern)\n",
+ " qp.setBrush(brush)\n",
+ " qp.drawRect(130, 15, 90, 60)\n",
+ "\n",
+ " \n",
+ " image = QtGui.QImage(\"C:/Users/Public/Pictures/Sample Pictures/Chrysanthemum.jpg\")\n",
+ " brush.setTextureImage (image)\n",
+ " qp.setBrush(brush)\n",
+ " qp.drawRect(250, 15, 90, 60)\n",
+ "\n",
+ " \n",
+ " \n",
+ " \n",
+ "def main():\n",
+ " \n",
+ " app = QtGui.QApplication(sys.argv)\n",
+ " ex = Example()\n",
+ " sys.exit(app.exec_())\n",
+ "\n",
+ "\n",
+ "if __name__ == '__main__':\n",
+ " main()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Displaying a Bitmap, Page number: 605<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to display a image in a window.'''\n",
+ "\n",
+ "from tkinter import *\n",
+ "\n",
+ "\n",
+ "top = Tk()\n",
+ "top.title(\"Pen styles\")\n",
+ "C = Canvas(top, height=300, width=500)\n",
+ "filename = PhotoImage(file = \"C:/Users/Akshatha M/Desktop/dialog1.gif\")\n",
+ "image = C.create_image(50, 50, anchor=NE, image=filename)\n",
+ "C.pack()\n",
+ "top.mainloop()\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "<h3>Animation at Work, Page number: 608<h3>"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "'''Program to illustrate a animation of a ball bouncing off a window '''\n",
+ "from visual import *\n",
+ "\n",
+ "floor = box(length=4, height=0.5, width=4, color=color.blue)\n",
+ "\n",
+ "ball = sphere(pos=(0,4,0), color=color.red)\n",
+ "ball.velocity = vector(0,-1,0)\n",
+ "\n",
+ "dt = 0.01\n",
+ "while 1:\n",
+ " rate(100)\n",
+ " ball.pos = ball.pos + ball.velocity*dt\n",
+ " if ball.y < 1:\n",
+ " ball.velocity.y = -ball.velocity.y\n",
+ " else:\n",
+ " ball.velocity.y = ball.velocity.y - 9.8*dt\n"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file |