example code sought

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sean McIlroy

    #1

    example code sought

    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
  • Gary Richardson

    #2
    Re: example code sought


    "Sean McIlroy" <sean_mcilroy@y ahoo.com> wrote in message
    news:e5063e96.0 412181041.1eb00 56a@posting.goo gle.com...[color=blue]
    > 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[/color]

    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(s elf, event):
    x, y = event.x, event.y
    dx = x - self.xLast
    dy = y - self.yLast
    for c in self.selectedCo mponents:
    for k in range(c.count):
    self.canvas.mov e(c.tags[k], dx, dy) # Move each piece of the
    component
    self.xLast, self.yLast = x, y


    Comment

    Working...