The first stage of the fun-learning Python pinball game

Source: Internet
Author: User

Recently, I read a book called "Fun Learning python--teach children to learn programming", which is very suitable for me who never write code.

Today began to follow the book, learn to write the first game of life: Pinball.

The code is just the beginning, just a window and a red ball 650) this.width=650; "src=" Http://img.baidu.com/hi/jx2/j_0057.gif "alt=" j_0057.gif "/ >

from tkinter import *import randomimport time# Create Ball class class ball:     def __init__ (Self,canvas,color):     #初始化函数 with canvas and color parameters          self.canvas = canvas    # Assign the parameter canvas to the object variable Canvas        self.id = canvas.create_oval ( 10, 10, 25, 25, fill=color)      #创建椭圆, upper-left and lower-right XY coordinates, returning id   representing the graphic       self.canvas.move (self.id, 245,100)     # The center of the canvas in which the painted oval is moved, the graphic is represented by the ID     def draw (self):         pass        #创建游戏的桌布tk  = tk ()     # Create a Tk object with the TK () class, a Tk object that is a basic window that can add something else to the window tk.title ("Game")      #给Tk对象窗口加一个标题tk. Resizable ( 0,0)      #tk窗口大小不可调整tk. Wm_attribUtes ("-topmost", 1)      #告诉tkinter把窗口放到最前面canvas  = canvas (tk, width=500,  heigh=400, bd=0, highlightthickness=0)      #Canvas是一个画布类canvas. Pack ()       #按照上面一行指定的宽度高度参数调整其自身大小tk. Update () #画一个红色的球ball  = ball (canvas, ' red ')       #用Ball类在画布上画一个红色的球 # main loop, let Tkinter continue to redraw the screen while 1:    tk.update_idletasks ()     tk.update ()     time.sleep (0.01)


The first stage of the fun-learning Python pinball game

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.