In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-21 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
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!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 215
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.