wxPython graphics query (newbie)

Thomas G stuff at greenery.me.uk
Mon Mar 17 08:03:08 EDT 2008


I am exploring wxPython and would be grateful for some help.

It is important to me to be able to slide words and shapes around by 
dragging them from place to place. I don't mean dragging them into a 
different window, which is what 'Drag and Drop' has come to mean, just 
moving them around within a canvas-like space.

This is easy using Tkinter. Can anybody offer me a tiny, very simple 
example of how it would be done in wxPython, please?

To make sure I convey what I'm looking for, here is what it looks like 
using Tkinter, written very simply. What I'm looking for is the same, 
quite simple functionality expressed in wxPython, again written very 
simply so that I can easily understand it.



#!/usr/bin/python
from Tkinter import *

root = Tk()

global canv


def makeFrame(root):
   global canv
   canv = Canvas (root, height = 200, width = 350)
   canv.create_text(100, 100, text='drag me', tags=('movable'))
      
   canv.tag_bind('movable', '<B1-Motion>', slide) #B1-motion is a drag 
with left button down
   canv.pack()

def slide (event):
   '''
   triggered when something is dragged on the canvas - move thing under 
mouse ('current') to new position
   '''
   newx = event.x
   newy = event.y
   canv.coords('current', newx, newy)

makeFrame(root)
root.mainloop()


Many thanks in advance

-- Thomas Green



More information about the Python-list mailing list