python - What is the difference between command and bind in tkinter? -
i'm trying make button print string when it's pressed , print when it's released. know command
atribute , bind
method, know if it's possible accomplish using atributes or if have use methods. piece of code:
class motor: def __init__(elemesmo, eixo , valorzero): elemesmo.eixo = eixo elemesmo.zero = valorzero def aumenta(self): print(self.eixo + str(self.zero+5)) def diminui(self): print(self.eixo + str(self.zero-5)) def para(self): print(self.eixo + str(self.zero)) eixox = motor('x',90) eixoy = motor('y',90) class interface: def __init__(elemesmo, widget): quadro = frame(widget) quadro.pack() elemesmo.aumentary = button(quadro,text="aumentar y",height=10,width=20,command=eixoy.aumenta) elemesmo.aumentary.pack(side=top) elemesmo.diminuiry = button(quadro,text="diminuir y",height=10,width=20,command=eixoy.diminui)
i can call method aumenta
object eixo y
when button aumentary
pressed. call method para
object eixo y
when button aumentary
released. how can it?
all event types outlined here, looking <button-1>
(click down on button 1 (left mouse button if right handed)) , <buttonrelease-1>
(release mouse button 1 (left button if right handed))
note wouldn't use command
if bind both of these.
elemesmo.aumentary = button(quadro,text="aumentar y",height=10,width=20) elemesmo.aumentary.bind("<button-1>",eixoy.aumenta) elemesmo.aumentary.bind("<buttonrelease-1>",eixoy.para)
however must know when using bind
callback called event object, if don't need can add optional , unused parameter callback:
def aumenta(self, event=none): print(self.eixo + str(self.zero+5)) def diminui(self, event=none): print(self.eixo + str(self.zero-5)) def para(self, event=none): print(self.eixo + str(self.zero))
Comments
Post a Comment