This is my first time creating a GUI using Tkinter to simulate a DSP setup. I'm stuck.
This GUI requires multiple scales. Therefore I wrote a generic scale function.
# Overlap percent scale
def overlap_percent():
print("Testing")
# op=var.get()
# olive_features['overlap_perc']=op
# generic scale function
def create_scale(self,parent,xval,yval,start,end,resolution,orient,default,lng,clr,cmdtrig):
OHA_scale = tk.Scale(parent,resolution=resolution, from_=start, to=end, orient=orient,length=lng,fg=clr,command=cmdtrig)
OHA_scale.grid(row=xval, column=yval, sticky=tk.E + tk.W + tk.N + tk.S, padx=20, pady=4)
OHA_scale.set(default)
# Overlap %
yval=yval+2
xval=1
self.create_label(Oliveframe,xval,yval,"Overlap %")
xval=3
self.create_scale(Oliveframe,xval,yval,25,75,25,"vertical",75,90,'Black',"overlap_percent")
xval=1
yval=yval+1
self.create_arrow(Oliveframe,xval,yval)
Based on the code above, i figured it would print 'Testing' on the cmd line, when i adjust the Overlap scale. Nothing happened. To test the code, i replaced the command in generic scale to
def create_scale(self,parent,xval,yval,start,end,resolution,orient,default,lng,clr,cmdtrig):
OHA_scale = tk.Scale(parent,resolution=resolution, from_=start, to=end, orient=orient,length=lng,fg=clr,command=overlap_percent)
This resulted in an error.
OHA_scale = tk.Scale(parent,resolution=resolution, from_=start, to=end, orient=orient,length=lng,fg=clr,command=overlap_percent) NameError: name 'overlap_percent' is not defined
I can't quite figure out what I'm doing wrong. How exactly can i use the generic scale function to control multiple scales?

overlap_percent()is within the class, thenself.overlap_percentshould be used instead.overlap_percent()wrong, should bedef overlap_percent(self, value)instead.name, tocreate_scale(...):def create_scale(..., cmdtrig, name):and pass the name to the generic function:tk.Scale(..., command=lambda v: cmdtrig(name, v). Then define the generic function likedef some_function(self, scale_name, value):. You can then create scales likecreate_scale(..., self.some_function, 'scale1'),create_scale(..., self.some_function, 'scale2')and etc.