Page 254 - Em Học Python
        P. 254
     =
                                    0
                        elf.x
                         s
                                                 s
                         s
                                               =
                        elf.canvas_width    elf.canvas.winfo_width()
                                                                       ,
                        elf.canvas.bind_all( <KeyPress-Left>'   elf.turn_left)
                                                  '
                                                                         s
                         s
                                                  '
                         s
                        elf.canvas.bind_all( <KeyPress-Right>'   elf.turn_right)
                                                                        ,
                                                                          s
                         d
                    ef  raw self):
                    d
                              (
                        elf.canvas.move(self.id,  elf.x,  )
                                                                  0
                         s
                                                        s
                         p
                                s
                        os    elf.canvas.coords(self.id)
                              =
                         i
                             p
                                     <
                                         0
                        f  os[0]  =  :
                              s
                            elf.x
                                         0
                                      =
                               p
                         e
                                           s
                                       >
                        lif  os[2]  =  elf.canvas_width:
                            elf.x
                                         0
                              s
                                      =
                         t
                                            e
                    ef  urn_left self,  vt):
                                    (
                    d
                                 =
                                    -
                         s
                        elf.x    2
                                             e
                         t
                                     (
                    ef  urn_right self,  vt):
                    d
                                 =
                                    2
                        elf.x
                         s
               tk    k()
                   =
                     T
               tk.title( Game"
                          "
                                 )
                                   0
               tk.resizable(0,  )
                                    "
               tk.wm_attributes( -topmost"   )
                                                ,
                                                  1
                                       w
                                                                          h
                          C
               canvas    anvas(tk,  idth=500,  eight=400,  d=0,  ighlightthickness=0)
                        =
                                                                   b
                                                     h
               canvas.pack()
               tk.update()
                                                   )
                        =
               paddle    addle(canvas,  blue'
                          P
                                            '
                                       p
                                                       )
                        B
               ball    all(canvas,  addle,  red'
                     =
                                                 '
               while  :
                       1
                                           =
                                                     :
                                               F
                    f  all.hit_bottom  =  alse
                        b
                    i
                        all.draw()
                         b
                        addle.draw()
                         p
                    t
                    k.update_idletasks()
                    t
                    k.update()
                    t
                    ime.sleep(0.01)
               TÓM  TẮT
                       Như  vậy,  chương  này  đã  kết  thúc  và  game  đầu  tiên  của  chúng
               ta  với  module  tkinter đã  hoàn  thiện.  Ta  đã  tạo  ra  một  lớp  mới  cho
               thanh  đỡ,  và  sử  dụng  rất  nhiều  toạ  độ  để  kiểm  tra  xem  bóng  có  đập
               vào  tường  hay  đập  vào  thanh  đỡ  không.  Ta  đã  sử  dụng  các  liên  kết  sự
               228           Chương  14





