Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

Code sharing of pinball Mini Game with Python

Shulou Source: shulou.com Published: 2022-06-02 05:12:50 09月29日 Update

This article mainly explains "Python to achieve pinball Mini Game code sharing", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "Python pinball Mini Game code sharing" bar!

The realization of the whole game is relatively simple, only need to install python on the computer to run, play the game, through the keyboard keys to control the movement of the pinball baffle. Don't say much about the principle, let's go and have a look.

1. After the code runs, the game interface is as follows:

2. After the game is over, the interface is as follows:

Part of the source code of the game is as follows:

Def main (): tk = tkinter.Tk () # callback for Quit def callback (): if mb.askokcancel ("Quit", "Do you really wish to quit?"): Ball.flag = False tk.destroy () tk.protocol ("WM_DELETE_WINDOW", callback) # Init parms in Canvas canvas_width = 600canvas_hight = 500tk.title ("pinball game V1") tk.resizable (0 0) tk.wm_attributes ("- topmost", 1) canvas = tkinter.Canvas (tk, width=canvas_width, height=canvas_hight, bd=0, highlightthickness=0, bg='#00ffff') canvas.pack () tk.update () score = Score (canvas, 'red') paddle = Paddle (canvas, "magenta") ball = Ball (canvas, paddle, score, "grey") game_over_text = canvas.create_text (canvas_width / 2, canvas_hight / 2 Text='Game over', state='hidden', fill='red', font= (None, 18, "bold") introduce = 'Welcome to version V1 of the pinball game:\ nClick any key-start\ nstop-enter key\ ncontinue-enter key\ n'game_start_text = canvas.create_text (canvas_width / 2, canvas_hight / 2, text=introduce, state='normal') Fill='magenta', font= (None, 18, "bold") while True: if (ball.hit_bottom = = False) and ball.paddle.started: canvas.itemconfigure (game_start_text State='hidden') ball.draw () paddle.draw () if ball.hit_bottom = = True: time.sleep (0.1) canvas.itemconfigure (game_over_text State='normal') tk.update_idletasks () tk.update () time.sleep (.01) if _ _ name__ = ='_ main__': main () Thank you for your reading The above is the content of "Python to achieve pinball Mini Game code sharing". After the study of this article, I believe you have a deeper understanding of the problem of Python to achieve pinball Mini Game code sharing, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Pinball code Mini Game learning content enter key interface operation principle just that is ideas situations bezels articles more game interface source code playing games computer Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB OPPO Reno macOS MySQL NVidia