By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,442 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,442 IT Pros & Developers. It's quick & easy.

example code sought

P: n/a
There's something quite simple I'd like to do, but I'm hampered by
lack of knowledge regarding Tkinter. If someone could help me out with
a snippet of maximally-simple code showing, in general terms, how to
do this, that would be really great. What I want to do is simply to
move a shape around on the screen using the mouse. I've looked at
Tkdnd.py but I can't seem to extract what I need from the more
involved stuff in there.

Peace,
STM
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a

"Sean McIlroy" <se**********@yahoo.com> wrote in message
news:e5**************************@posting.google.c om...
There's something quite simple I'd like to do, but I'm hampered by
lack of knowledge regarding Tkinter. If someone could help me out with
a snippet of maximally-simple code showing, in general terms, how to
do this, that would be really great. What I want to do is simply to
move a shape around on the screen using the mouse. I've looked at
Tkdnd.py but I can't seem to extract what I need from the more
involved stuff in there.

Peace,
STM


Use Canvas.move(). Here is some code from a program of mine that may give
you an idea of how to go about this. In my case each component consisted of
several pieces, each having a unique tag. If they had had the same tag only
one move command would have been needed. self.xLast and self.yLast need to
be initialized to the current cursor position before the move starts.

def onMouseMotion(self, event):
x, y = event.x, event.y
dx = x - self.xLast
dy = y - self.yLast
for c in self.selectedComponents:
for k in range(c.count):
self.canvas.move(c.tags[k], dx, dy) # Move each piece of the
component
self.xLast, self.yLast = x, y
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.