473,602 Members | 2,811 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

happy (tkinter) easter 2007 folks!

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....

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 5925

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

Similar topics

5
2130
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
4
6352
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:...
1
3335
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
2
3384
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... --
4
259
by: Jorge | last post by:
Hi I wish You all an happy easter hollidays. Jorge
2
5369
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...
0
1156
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 well.... import Tkinter import random import colorsys import time # Happy easter 2007 folks! from kudos@spray.no
4
4156
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.
0
1407
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 import random import time #hc&hy kudos@spray.no
0
7993
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, 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...
0
8404
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 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...
1
8054
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,...
0
8268
tracyyun
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...
0
6730
agi2029
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...
1
5867
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 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...
0
5440
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();...
1
1510
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1254
bsmnconsultancy
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...

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.