473,322 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software 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 1125

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
3
by: Thomas Ploch | last post by:
Hello folks, Since this is my first post on the list, a brief introduction of myself. My name is Thomas, I am 26 years old, I am a student of Computational Linguistics and I am a python...
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: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.