All of that changes are inside the move_ball method. ![]() I've modified your program slightly by removing the infinite loop, slowing down the animation a bit, and also using random values for the direction they move. With that, your balls will continue to move forever (which means you should put some sort of check in there to prevent that from happening) If you want your balls to move independently, simply take out the loop and have the move_ball method put a new call to itself on the event loop. You should never put an infinite loop inside a GUI program - there's already an infinite loop running. # create two ball objects and animate them ![]() Self.ball = canvas.create_oval(self.x1, self.y1, self.x2, self.y2, fill="red")Ĭanvas = Canvas(root, width = 300, height = 300) This is my code that is only animating/moving one ball: from Tkinter import *ĭef _init_(self, canvas, x1, y1, x2, y2): I have tried some variations as well but can't get the second ball moving another related question - some people use the move(object) method to achieve this, while others do a delete(object) and then redraw it. The task is to bring that bar to a suitable location by moving left or right so that the red ball will fall on that bar(catch the ball onto the bar) not on the ground.This is a very basic program with which I want to make two moving balls, but only one of them actually moves. Red ball will continuously fall from top to bottom and can start from any random x-axis distance. There is one bar at the bottom of game window which can be moved left or right using the buttons that are in the game window. Let’s try to develop a simple Catching the ball game using Python and TKinter. Python can also be used to develop different type of game. Python is a multipurpose language and can be used in almost every field of development. Twitter Sentiment Analysis using Python.Python | Simple GUI calculator using Tkinter.Implementing Web Scraping in Python with BeautifulSoup.SDE SHEET - A Complete Guide for SDE Preparation.Python | Shuffle two lists with same order.Python | Scramble words from a text file.Python | Program to implement Jumbled word game.Look sharp, because it happens fast: your player falls out of the sky, right off your game screen. In this code, add the first line to your loop: avity () check gravity player.update () Launch your game to see what happens. Python implementation of automatic Tic Tac Toe game using random number This way, Python applies the falling motion to your player once every clock tick. ![]()
0 Comments
Leave a Reply. |