0
Play with Python     Lecture 2
AgendaRevisionObject Oriented ProgrammingDemo 1Demo 2Demo 3 (GUI)AssignmentNext Week !
RevisionLists  empty list:       lst = []  list of lists:       lofl = [[1,2],[3,4]]  list of different types: lst2 = [1, ...
Object Oriented ProgrammingApplication is a set of objects
Object Oriented ProgrammingApplication is a set of living objects
Object Oriented ProgrammingApplication is a set of living interacting objects
Object Oriented ProgrammingApplication is a set of living interacting objects
Data + BehaviourApplication is a set of living interacting objects
Demo 1 (Animals)c = Cat()c.talk()c.walk()
Demo 1 (Animals)c = Cat()c.talk()c.walk()d = Duck()d.talk()d.fly()
Demo 1 (Animals)c = Cat()           m = Mouse()c.talk()            m.die()c.walk()d = Duck()d.talk()d.fly()
Demo 1 (Animals)c = Cat()           m = Mouse()c.talk()            m.die()c.walk()d = Duck()d.talk()d.fly()
Demo 1 (Animals eating)c = Cat()c.talk()c.walk()c.eat(m)c2 = Cat()c2.eat(b)
Demo 1 (Animals)c = Cat()           m = Mouse()c.talk()c.walk()c.eat(m)            b = Bread()c2 = Cat()c2.eat(b)
Demo 1 Classes (Animals)class Cat:                     class Mouse:   def talk(self):                    def die(self):   ...
Demo 1: List of Animalsanimals = []             animals list is also ananimals.append(Cat())      object of class "List" !...
Demo 2 (Computer Device)
Demo 2 (Computer Device)class Computer:                        Constructor  def __init__(self, computer_type, basePrice): ...
GUI with PyQt4
GUI Exampledlg = QDialog()btn = QPushButton("Click Me !", dlg)btn.clicked.connect(onButtonClicked)btn2 = QPushButton("Clic...
GUI Example (Added an image)dlg = QDialog()                               dlg.show()dlg.resize(500, 500)                  ...
Upcoming SlideShare
Loading in...5
×

Play with python lecture 2

337

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
337
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
4
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Play with python lecture 2"

  1. 1. Play with Python Lecture 2
  2. 2. AgendaRevisionObject Oriented ProgrammingDemo 1Demo 2Demo 3 (GUI)AssignmentNext Week !
  3. 3. RevisionLists empty list: lst = [] list of lists: lofl = [[1,2],[3,4]] list of different types: lst2 = [1, "hi"]Dictionary: empty dictionary: d = {}
  4. 4. Object Oriented ProgrammingApplication is a set of objects
  5. 5. Object Oriented ProgrammingApplication is a set of living objects
  6. 6. Object Oriented ProgrammingApplication is a set of living interacting objects
  7. 7. Object Oriented ProgrammingApplication is a set of living interacting objects
  8. 8. Data + BehaviourApplication is a set of living interacting objects
  9. 9. Demo 1 (Animals)c = Cat()c.talk()c.walk()
  10. 10. Demo 1 (Animals)c = Cat()c.talk()c.walk()d = Duck()d.talk()d.fly()
  11. 11. Demo 1 (Animals)c = Cat() m = Mouse()c.talk() m.die()c.walk()d = Duck()d.talk()d.fly()
  12. 12. Demo 1 (Animals)c = Cat() m = Mouse()c.talk() m.die()c.walk()d = Duck()d.talk()d.fly()
  13. 13. Demo 1 (Animals eating)c = Cat()c.talk()c.walk()c.eat(m)c2 = Cat()c2.eat(b)
  14. 14. Demo 1 (Animals)c = Cat() m = Mouse()c.talk()c.walk()c.eat(m) b = Bread()c2 = Cat()c2.eat(b)
  15. 15. Demo 1 Classes (Animals)class Cat: class Mouse: def talk(self): def die(self): print " !! " print " " def walk(self): class Bread: print " " def die(self): print “” ” def eat(self, something): something.die() print " "
  16. 16. Demo 1: List of Animalsanimals = [] animals list is also ananimals.append(Cat()) object of class "List" !animals.append(Duck())for a in animals: a.talk()
  17. 17. Demo 2 (Computer Device)
  18. 18. Demo 2 (Computer Device)class Computer: Constructor def __init__(self, computer_type, basePrice): self.computerType = computer_type Member
  19. 19. GUI with PyQt4
  20. 20. GUI Exampledlg = QDialog()btn = QPushButton("Click Me !", dlg)btn.clicked.connect(onButtonClicked)btn2 = QPushButton("Click Me Too !!", dlg)btn2.move(100,0)btn2.clicked.connect(onButton2Clicked)dlg.show()def onButtonClicked(): print "Hello World"def onButton2Clicked(): btn.close()
  21. 21. GUI Example (Added an image)dlg = QDialog() dlg.show()dlg.resize(500, 500) def onButtonClicked():btn = QPushButton("Click Me !", dlg) print "Hello World"btn.clicked.connect(onButtonClicked) def onButton2Clicked(): btn.close()btn2 = QPushButton("Click Me Too !!", dlg)btn2.move(100,0)btn2.clicked.connect(onButton2Clicked)label = QLabel("My First GUI program", dlg)pix = QPixmap("Water lilies.jpg")label.setPixmap(pix)
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×