Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

tkinter question

4 views
Skip to first unread message

Eric_...@msn.com

unread,
Oct 3, 2008, 9:44:08 AM10/3/08
to
I saw this (close to this anyway) lieing around on the internet and
was wanting to use it to define a start point exc but I need the
graphics to stay within a set y coords and I am not realy sure how to
do that. I have no idea on how to bind a min/max y to it. (the
concept is inspired by the java csound blue).


#!/usr/bin/python
from Tkinter import *
import csoundroutines as cs


root = Tk()


global canv
xx = {}

def makeFrame(root):
global canv
test = cs.csdInstrumentlist3('bay-at-night.csd')
canv = Canvas (root, height = 200, width = 350)

for i in range (0, len(test.instr_number)):
canv.create_text(10, i *10, text=str(test.instr_number[i]) +
'...', tags=('movable'))
xx[i] = 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
if event.y < 10 and event.y > 0:
newy = event.y
canv.coords('current', newx, newy)


makeFrame(root)
root.mainloop()

Chuckk Hubbard

unread,
Oct 26, 2008, 9:02:20 AM10/26/08
to pytho...@python.org
Hello.
How about this? I changed the if statements so the coordinates are
always updated, but only changed if within the right limits, otherwise
updated to the existing value. Now if you drag outside the limits of
one dimension, it still moves in the other dimension. Not sure if
that's what you want. I'm amazed that this can be so simple, I came
up with an intricate system for my app, not realizing I could bind
events to canvas items!
BTW, I've never come across csoundroutines, can you give me a synopsis
of what it's for? I'm using the Python Csound API. This is why I
commented out all the references to csoundroutines, I don't have it
installed at the moment.
-Chuckk

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

#import csoundroutines as cs


root = Tk()


global canv
xx = {}

def makeFrame(root):
global canv
# test = cs.csdInstrumentlist3('bay-at-night.csd')


canv = Canvas (root, height = 200, width = 350)

# for i in range (0, len(test.instr_number)):
for i in range (0, 4):
# canv.create_text(10, i *10, text=str(test.instr_number[i]) +
canv.create_text(10, i *10, text=str(i) +


'...', tags=('movable'))
xx[i] = 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
'''

if 0 < event.x < 200:
newx = event.x
else: newx = canv.coords('current')[0]
if 0 < event.y < 100:
newy = event.y
else: newy = canv.coords('current')[1]


canv.coords('current', newx, newy)


makeFrame(root)
root.mainloop()

> --
> http://mail.python.org/mailman/listinfo/python-list
>

--
http://www.badmuthahubbard.com

Eric_...@msn.com

unread,
Dec 1, 2008, 3:39:08 AM12/1/08
to
On Oct 26, 7:02 am, "Chuckk Hubbard" <badmuthahubb...@gmail.com>
wrote:

> Hello.
> How about this?  I changed the if statements so the coordinates are
> always updated, but only changed if within the right limits, otherwise
> updated to the existing value.  Now if you drag outside the limits of
> one dimension, it still moves in the other dimension.  Not sure if
> that's what you want.  I'm amazed that this can be so simple, I came
> up with an intricate system for my app, not realizing I could bind
> events to canvas items!
> BTW, I've never come across csoundroutines, can you give me a synopsis
> of what it's for?  I'm using thePythonCsoundAPI.  This is why I
> --http://www.badmuthahubbard.com- Hide quoted text -
>
> - Show quoted text -

sorry to take so long to reply... You should be able to find the
latest version of csound routines in the csound blog.. an older
version is in dex tracker available on source forge..

Eric_...@msn.com

unread,
Dec 1, 2008, 3:41:40 AM12/1/08
to
On Oct 26, 7:02 am, "Chuckk Hubbard" <badmuthahubb...@gmail.com>
wrote:
> Hello.
> How about this?  I changed the if statements so the coordinates are
> always updated, but only changed if within the right limits, otherwise
> updated to the existing value.  Now if you drag outside the limits of
> one dimension, it still moves in the other dimension.  Not sure if
> that's what you want.  I'm amazed that this can be so simple, I came
> up with an intricate system for my app, not realizing I could bind
> events to canvas items!
> BTW, I've never come across csoundroutines, can you give me a synopsis
> of what it's for?  I'm using thePythonCsoundAPI.  This is why I
> --http://www.badmuthahubbard.com- Hide quoted text -
>
> - Show quoted text -

haven't tried this yet but I look foward to trying it out..

0 new messages