0

First time posting to stackoverflow so i'll try to get this right...

I'm running a data acquisition module in python who's input data stream is the output of a different python module. Tkinter sliders are used to control: the scale of the x-axis of the plot (which is plotting the incoming data), and 'generation speed':

for axisnum in range( len( subplots ) ):
    wScale  = Tkinter.Scale( master = roots[root],
                             label  = "View Width on Plot %s:" % ( axisnum ),
                             from_  = 3, to = 1000,
                             orient = Tkinter.HORIZONTAL,
                             sliderlength   = 30,
                             length = subplots[axisnum].get_frame().get_window_extent().width,
                             )
    wScale2 = Tkinter.Scale( master = roots[root],
                             label  = "Generation Speed for Plot %s:" % ( axisnum ),
                             from_  = 1, to = 200,
                             orient = Tkinter.HORIZONTAL,
                             sliderlength   = 30,
                             length = subplots[axisnum].get_frame().get_window_extent().width
                             )
    wScale2.pack( side = Tkinter.BOTTOM )
    wScale.pack(  side = Tkinter.BOTTOM )
    wScale.set(   100 )
    wScale2.set(  wScale2['to'] - 3 )

The problem is that, though this creates all 'n' pairs of slider widgets on the canvas only the first is actually active and moreover acts as a 'master slider' controlling all 'n' subplots simultaneously.

Slight modifications have led to the 'x and y data must be same length' being raised.

So any suggestions on how I can create tkinter sliders which control the scale of the x-axis of individual subplots on a single figure?

Update

Perhaps the problem could be in my RealtimePlotter?

Note dsets[Figure][subs][data] will get you the data points for a specific subplot; subs should typically be left at '0'.

    def RealtimePlotter():
      global dsets, wScalesList, wScales2List
      for i in range(len(Figures_List)):
          for Scale in wScalesList:
             Samples = min(len(dsets[i][0][0]),Scale[0].get())
             XAxis = pylab.arange(len(dsets[i][0][0])-Samples, 
                                  len(dsets[i][0][0], 1
                                  )
             for t in range(len(linenum)-1):
             #we choose lineax and axnum[1] because [0] is just the figure number
                 (lineax[t+1])[i].set_data(XAxis,pylab.array(dsets[i][0][t][-Samples:])
                 (axinfo[t+1]).axis([XAxis.min(),Xaxis.max(),-1.5,1.5])
          for canvas in range(len(canvasList)):
              canvasList[canvas].draw()
          for root in range(len(roots)):
              roots[root].after(100,RealtimePlotter) 
Luke
  • 1
  • 1
  • also, goes without saying I'm new to python – Luke Oct 30 '14 at 17:48
  • Welcome, Luke, you may get interested in >>> http://stackoverflow.com/a/26268733/3666197 and there derrogated example – user3666197 Oct 30 '14 at 17:52
  • unfortunately because I am being told to build off of someone else's code infrastructure I am limited to modifying what is already in front of me, which are pretty strict confines – Luke Oct 30 '14 at 18:49
  • I'm not a Tkinter expert, but the behavior you have suggests that the issue stems from not keeping the Scale instances distinct (you're "overwriting" wScale and wScale2 in your loop). Perhaps try forming and filling a couple of widget lists instead? – Ajean Oct 30 '14 at 20:29

1 Answers1

0

There is no problem with the example below so there must be something in your code that I am not able to duplicate. When you say "canvas" are the sliders on a canvas object or is that just a figure of speech. Also, which type of object is roots[root].

"only the first is actually active and moreover acts as a 'master slider' controlling all 'n' subplots simultaneously" I think that the only way this is possible is if they all point to the same object.

import Tkinter
root=Tkinter.Tk()
root.geometry("225x150")

for slide_length in (200, 150):
    wScale  = Tkinter.Scale( master = root,
                         label  = "View Width on Plot ",
                         from_  = 3, to = 1000,
                         orient = Tkinter.HORIZONTAL,
                         sliderlength   = 30,
                         length = slide_length)
    wScale.pack(side = Tkinter.BOTTOM)
root.mainloop()
  • To clarify, the sliders are in fact on a canvas object. roots is a list of roots, i.e Tkinter.Tk() Tkinter.Toplevel(), such that I can have multiple data acquisition figures open at once. – Luke Nov 03 '14 at 15:02