python - How to make some buttons call methods from previous classes in tkinter? -
i used tkinter set 4 buttons, , want print different strings @ each button press. when run code, got 4 different strings printed(one of each) @ once without pressing of them , when press, nothing happens. here's code:
from tkinter import * 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)) def paratudo(): motor.para(eixox) motor.para(eixoy) eixox = motor('x',90) eixoy = motor('y',90) class interface: def __init__(elemesmo, widget): quadro = frame(widget) quadro.pack() elemesmo.aumentarx = button(quadro,text="aumentar x",height=10,width=20,command=eixox.aumenta()) elemesmo.aumentarx.pack(side=right) elemesmo.diminuirx = button(quadro,text="diminuir x",height=10,width=20,command=eixox.diminui()) elemesmo.diminuirx.pack(side=left) 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()) elemesmo.diminuiry.pack(side=top) widget = tk() app = interface(widget) widget.mainloop()
also, run paratudo()
when button released, independently button released, know command
option.
the functions being called button
widgets created.
...command=eixox.aumenta()) ^^
including parentheses calls function , binds command
returned result of function. don't want that. want give button
actual function. call function when click it.
...command=eixox.aumenta)
Comments
Post a Comment