473,395 Members | 1,554 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,395 software developers and data experts.

creating an oval when clicking on a canvas by means of a mouse

3
Hi!! Actually,i am doing a simulation and i want a dot (small oval) to pop up when i click(by mouse) on the canvas.
can anyone please help me or if possible give me the piece of codes to perform this.
thanks in advance...

from Tkinter import *
import Tkinter
from Tkconstants import *
import random


frame=Tkinter.Frame()
frame.pack()



canvas =Tkinter.Canvas(frame,bg = 'white',width=200, height=400)
canvas.pack()



def generate():
for i in range(50):

x1=random.randrange(500)
y1=random.randrange(500)
x2=x1+5
y2= y1+5

canvas.create_oval(x1,y1,x2,y2,fill ="red")







button=Tkinter.Button(frame,fg="blue", text="GENERATE", activebackground='red',font=('verdana', 10, 'bold'),command=generate).pack(padx =50,side = LEFT)



root = Tkinter.Tk()


root.mainloop()
Feb 4 '08 #1
1 1744
Hey,
Check out http://effbot.org/tkinterbook/, it has a bunch of info on canvas's and other widgets.


Expand|Select|Wrap|Line Numbers
  1. from Tkinter import *
  2. import random
  3.  
  4. root = Tk()
  5. frame = Frame(root)
  6. frame.pack()
  7. global c
  8. c = Canvas(frame, width=200, height=200)
  9. c.pack()
  10. def generate(event):
  11.   r1 = random.randint(1,200)
  12.   r2 = random.randint(1,200)
  13.   r3 = r1+5
  14.   r4 = r2+5
  15.   coords = r1,r2,r3,r4
  16.   c.create_oval(coords, fill="red")
  17. c.bind('<Button-1>', generate)
  18. mainloop()
  19.  
I made a few changes, and it works for me. (I'm running python 2.5 on XP)
Feb 5 '08 #2

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

Similar topics

3
by: Santhu | last post by:
I want to have a Pop Up Menu on a web form when i click right mouse button. I want to have some options in that menu as New ,Edit etc., . Suppose if i want to escape then i can escape it by pressing...
0
by: Tallgeese | last post by:
We developed an in-process COM object for our own application. A toolbar button is used to activate the COM object. But when the COM object loaded, the HTML help hang when clicking the "List...
3
by: Andrew Wrigley | last post by:
Hi I have what seems a corruption of an mdb that is not solved by the decompile command line trick. The problem appears when clicking on a subform control (check box) that has a event handler...
0
by: jeff | last post by:
is there a way to display an hourglass for the client's cursor when clicking a button running server-side code? thanks.
4
by: James Brett | last post by:
I have one form on the page but have multiple submit buttons for different elements. When clicking on a button not associated with the required elements the validator popup still comes up. How...
2
by: André | last post by:
Hi, I made a detailsview containing several fields for inserting only. I also made a dropdownlist which is invisible at start. Now, when clicking in a particular textbox, the dropdownlist must...
1
by: neelesh kumar | last post by:
sir, i have a form created using wizard from table questions.My problem is when i scroll the mouse next records are coming.can we avoid next records to come when we scroll the mouse.i want to be in...
8
by: AAaron123 | last post by:
If IE is open I'd like my app to receive an event or otherwise know when IE receives a mouse click. Is that fairly easy to do? Thanks in advance
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...

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.