wxPython graphics query (newbie)

T

Thomas G

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
 
M

Mike Driscoll

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

Hmmm...I'm not sure how to do that. Please post this same question to
the wxPython user's group. They'll know if anyone does:
http://wxpython.org/maillist.php

Mike
 
C

Chris Mellon

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.


See the floatcanvas and OGL examples in the wxPython demo.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,207
Latest member
Best crypto consultant

Latest Threads

Top