473,406 Members | 2,549 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes and contribute your articles to a community of 473,406 developers and data experts.

happy (tkinter) easter 2007 folks!

kudos
127 Expert 100+
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....

Expand|Select|Wrap|Line Numbers
  1. import Tkinter
  2. import random
  3. import colorsys
  4. import time
  5.  
  6. # Happy easter 2007 folks! from kudos@spray.no
  7.  
  8. playerx=170
  9. bar = 0
  10. ball = 0
  11. ballvx = ballvy = 0.1
  12. ballx = 200;
  13. bally = 150;
  14.  
  15. def motion(event):
  16.  global playerx
  17.  playerx = event.x
  18.  if(playerx < 400-60):
  19.   w.coords(bar,playerx,250,playerx+60,250)
  20. root = Tkinter.Tk()
  21. w = Tkinter.Canvas(root, width=400, height=300, background="#000000")
  22. w.bind("<Motion>", motion)
  23. ball = w.create_oval(ballx-3,bally-3,ballx+3,bally+3,fill="#cccccc") # ball
  24. blocks = []
  25. k = 0.0
  26. for j in range(10):
  27.  for i in range(10):
  28.   c =  colorsys.hsv_to_rgb(k,0.5,0.4)
  29.   d = hex(int(c[0]*256)<<16 | int(c[1]*256)<<8 | int(c[2]*256));
  30.   d = "#"+d[2:len(d)]
  31.   k+=0.01
  32.   blocks.append(w.create_rectangle(40*i,(j*10)+10,40+(40*i),20+(j*10),fill=d))
  33. bar = w.create_line(playerx,250,playerx+60,250,fill="#ffffff")
  34. w.pack()
  35. try:
  36.  while 1:
  37.   w.coords(ball,ballx-3,bally-3,ballx+3,bally+3)
  38.   if(ballx+ballvx > 400 or ballx+ballvx < 0):
  39.    ballvx*=(-1)
  40.   if(bally+ballvy < 0):
  41.    ballvy*=(-1)
  42.   for block in blocks:
  43.     crash = 0
  44.     co = w.coords(block)
  45.     if(ballx+ballvx > co[0] and ballx+ballvx < co[2] and bally > co[1] and bally < co[3]):
  46.      crash=1
  47.      ballvx*=(-1)
  48.     if(ballx > co[0] and ballx < co[2] and bally+ballvy > co[1] and bally+ballvy < co[3]):
  49.      crash=1
  50.      ballvy*=(-1)
  51.     if(crash == 1):
  52.      w.coords(block,-10,-10,-20,-20)
  53.   if( (bally > 248 and bally < 250) and (ballx > playerx and ballx < playerx + 60)):
  54.    ballvy*=-1
  55.   if(bally > 406):
  56.    ballvy = ballvx = 0.1
  57.    ballx = 200
  58.    bally = 150
  59.   ballx+=ballvx
  60.   bally+=ballvy
  61.   root.update_idletasks()
  62.   root.update()
  63. except Tkinter.TclError:
  64.  pass
  65.  
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
Mar 30 '07 #1
0 5901

Sign in to post your reply or Sign up for a free account.

Similar topics

5
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...
4
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...
1
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...
2
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...
4
by: Jorge | last post by:
Hi I wish You all an happy easter hollidays. Jorge
2
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...
0
kudos
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...
4
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...
0
kudos
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
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...
0
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.