tkinter question

E

Eric_Dexter

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) +
'...', tags=('movable'))
xx = 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()
 
C

Chuckk Hubbard

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) +
canv.create_text(10, i *10, text=str(i) +
'...', tags=('movable'))
xx = 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()


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) +
'...', tags=('movable'))
xx = 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()
 
E

Eric_Dexter

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
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) +
    canv.create_text(10, i *10, text=str(i) +
'...', tags=('movable'))
    xx = 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()





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 javacsoundblue).
#!/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) +
'...', tags=('movable'))
    xx = 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()

--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..
 
E

Eric_Dexter

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
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) +
    canv.create_text(10, i *10, text=str(i) +
'...', tags=('movable'))
    xx = 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()





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 javacsoundblue).
#!/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) +
'...', tags=('movable'))
    xx = 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()

--http://www.badmuthahubbard.com- Hide quoted text -

- Show quoted text -


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

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top