kudos 127
Recognized Expert New Member
Hi, a couple of months ago, I made a xmas chistmas "card" to this community( http://www.thescripts.com/forum/thread580722.html) Now its soon easter, and I hacked together something for easter as well.... -
import Tkinter
-
import random
-
import colorsys
-
import time
-
-
# Happy easter 2007 folks! from kudos@spray.no
-
-
playerx=170
-
bar = 0
-
ball = 0
-
ballvx = ballvy = 0.1
-
ballx = 200;
-
bally = 150;
-
-
def motion(event):
-
global playerx
-
playerx = event.x
-
if(playerx < 400-60):
-
w.coords(bar,playerx,250,playerx+60,250)
-
root = Tkinter.Tk()
-
w = Tkinter.Canvas(root, width=400, height=300, background="#000000")
-
w.bind("<Motion>", motion)
-
ball = w.create_oval(ballx-3,bally-3,ballx+3,bally+3,fill="#cccccc") # ball
-
blocks = []
-
k = 0.0
-
for j in range(10):
-
for i in range(10):
-
c = colorsys.hsv_to_rgb(k,0.5,0.4)
-
d = hex(int(c[0]*256)<<16 | int(c[1]*256)<<8 | int(c[2]*256));
-
d = "#"+d[2:len(d)]
-
k+=0.01
-
blocks.append(w.create_rectangle(40*i,(j*10)+10,40+(40*i),20+(j*10),fill=d))
-
bar = w.create_line(playerx,250,playerx+60,250,fill="#ffffff")
-
w.pack()
-
try:
-
while 1:
-
w.coords(ball,ballx-3,bally-3,ballx+3,bally+3)
-
if(ballx+ballvx > 400 or ballx+ballvx < 0):
-
ballvx*=(-1)
-
if(bally+ballvy < 0):
-
ballvy*=(-1)
-
for block in blocks:
-
crash = 0
-
co = w.coords(block)
-
if(ballx+ballvx > co[0] and ballx+ballvx < co[2] and bally > co[1] and bally < co[3]):
-
crash=1
-
ballvx*=(-1)
-
if(ballx > co[0] and ballx < co[2] and bally+ballvy > co[1] and bally+ballvy < co[3]):
-
crash=1
-
ballvy*=(-1)
-
if(crash == 1):
-
w.coords(block,-10,-10,-20,-20)
-
if( (bally > 248 and bally < 250) and (ballx > playerx and ballx < playerx + 60)):
-
ballvy*=-1
-
if(bally > 406):
-
ballvy = ballvx = 0.1
-
ballx = 200
-
bally = 150
-
ballx+=ballvx
-
bally+=ballvy
-
root.update_idletasks()
-
root.update()
-
except Tkinter.TclError:
-
pass
-
Note, I didn't include any kind of timer for this application, so if its slow/fast then increase/decrease ballvx and ballvy (or even better, write some code than handles timing :-)
-kudos
0 5925 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: eesun |
last post by:
Hi,
I've downloaded the dislin package for the scientific plotting. And I
have already created the application window with Tkinter (menu,
canvas, status bar..). I want to integrate the Dislin plotting into
the Tkinter application. For ex: show the dislin result on the Tkinter
Canvas. Anyone can help?
thx
|
by: Tim Jarman |
last post by:
Apologies in advance for the long post - I wanted to be sure I included all
the relevant details. The answer is probably very, very simple.
I am doing something stupid here, but I don't know what it is. I'm writing
an application with a Tkinter GUI (Python 2.4, Tcl/Tk 8.4.) and I want to
put a custom icon on the main window.
I've followed (so far as I understand it) the recipe in the eff-bot's
splendid Introduction to Tkinter - see:...
|
by: jimfortune |
last post by:
From:
http://groups-beta.google.com/group/comp.databases.ms-access/msg/769e67e3d0f97a90?hl=en&
Errata:
19 solar years = 2939.6018 days should be
19 solar years = 6939.6018 days
Easter Function explanation Part II
|
by: Gustavo G. Rondina |
last post by:
It is possible to caclulate every year's easter using simple
mathematical operations. Here is a code that does the trick:
http://www.brlivre.org/c/easter.c
I found the math scheme in an american scientific issue, march
2001. The article about the calendars is very interesting.
Have fun...
--
|
by: Jorge |
last post by:
Hi
I wish You all an happy easter hollidays.
Jorge
| |
by: Ben Finney |
last post by:
Howdy all,
Python programmers looking for a built-in GUI toolkit are told two
things: one, Python already comes with a GUI toolkit, and two, it
looks equally ugly on all platforms. This is because the Tk widget
library, that Tkinter uses, defaults to looking like Motif, which
hasn't been the default widget set of *anything* for a long time.
The Tk folks are apparently getting their act together. Tile is a
"theming engine" for Tk with...
|
by: kudos |
last post by:
Hi, a couple of months ago, I made a xmas chistmas "card" to this community(http://www.thescripts.com/forum/thread580722.html) Now its soon easter, and I hacked together something for easter as well....
import Tkinter
import random
import colorsys
import time
# Happy easter 2007 folks! from kudos@spray.no
|
by: Simon Forman |
last post by:
Hi all,
I realize this is more of a Tk question than a python one, but since
I'm using python and don't know Tcl/Tk I figured I'd ask here first
before bugging the Tcl folks.
I am having a terrible time trying to get a pack() layout working.
I have three frames stacked top to bottom and stretching across the
master window from edge to edge.
|
by: kudos |
last post by:
Its turned into a tradition, making small tkinter "cards". Here is one for the christmas and new year. Paste and run from python!
http://www.freewebs.com/jan_ma/look.png
import Tkinter
import random
import time
#hc&hy kudos@spray.no
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |