i have a promblem with GUI Tkinter, when i click the button of my gui enviroment the arm of my robot dont response more specific call the function but steal remaning in 0 degre``es from the other my code is fine because when i click from my keyboard 'w' my arm plus for each time i click the button 15 degrees. Really i dont know if i use the right button , i am beginner in the python and i need some advice. my code:
from Tkinter import *
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BOARD)
GPIO.setup(15,GPIO.OUT)
pwm = GPIO.PWM(15, 50)
pwm.start(0)
root = Tk ()
Label(root, text="ANgel").grid(row = 0)
e1 = Entry(root)
e1.grid(row = 0, column = 1)
i = 0
def Angle(angle):
#Calculate
duty = angle / 18 + 2
GPIO.output(15,True)
pwm.ChangeDutyCycle(duty)
time.sleep(0.3)
GPIO.output(15, False)
pwm.ChangeDutyCycle(0)
def servo_up(event):
#Servo lifts arm
global i
if event.keysym == 'w' and i < 180:
key_press = event.char
print "Key: ", event.char
i = i + 15
Angle(i)
print " ", i
else:
print "You are in the limit: ", i, "Degrees"
b1 = Button(root,text = 'quit', bg = "red", command = root.quit)
b1.grid(row = 2, column = 3)
b= Button(root, text="Arm Up")
b.bind("<Button-1>", servo_up)
b.grid(row=2, column = 1)
root.bind('<w>', servo_up)
root.mainloop()
GPIO.cleanup()
When i click the button from graphical enviroment, I'm getting:
You are in the limit: 0 Degrees
when i click the w from keyboard, it work:
Key: w
15
Key: w
30
Key: w
45
Thanks.
if event.keysym == 'w'
so it is falling through to theelse: