#!/bin/sh """:" exec python $0 ${1+"$@"} """ # --------------------- HelloCrosshairs.py -------------------- # # This program demonstrates all methods available for crosshairs. # Note that this program does not do anything useful; # its purpose is to try out functionality only. # from Tkinter import * # The Tk package import Pmw # The Python MegaWidget package import math # import the sin-function master = Tk() # build Tk-environment ncurves = 4 # draw 4 curves npoints = 32 # use 32 points on each curve if not Pmw.Blt.haveblt(master): # Is Blt installed? print("BLT is not installed!") else: vector_x = [] # make vector for x-axis vector_y = [] for y in range(ncurves): vector_y.append([]) for x in range(npoints+1): vector_x.append(x*0.1) # fill vectors with cool graphs for c in range(ncurves): vector_y[c].append(math.sin(c*x*0.1)) g = Pmw.Blt.Graph(master) g.pack(expand=1, fill='both') for c in range(ncurves): curvename = 'sin(' + str(c) +'x)' g.line_create(curvename, xdata=tuple(vector_x), ydata=tuple(vector_y[c]), symbol='') g.configure(title='Hello Crosshairs') ######################## crosshairs_cget ############################# if g.crosshairs_cget("hide"): print "the crosshairs are hidden" else: print "the crosshairs are visible" ###################### crosshairs_configure ########################## all = g.crosshairs_configure() print "all options:" for option in all.keys(): print option, "=", g.crosshairs_cget(option) print "\n" # show crosshairs g.crosshairs_configure( dashes="1", hide=0, linewidth=1, position="@120, 120", color="lightblue") ######################## crosshairs_toggle ########################## g.crosshairs_toggle() # hide the crosshairs ######################### crosshairs_off ############################ g.crosshairs_off() # hide the crosshairs (no effect - already hidden) ########################## crosshairs_on ############################ g.crosshairs_on() # show the crosshairs again # Normally we want to bind the crosshairs to the mouse like this: def mouseMove(event): pos = "@" +str(event.x) +"," +str(event.y) g.crosshairs_configure(position = pos) g.bind("<Motion>", mouseMove) master.mainloop()