#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    9
    Rep Power
    0

    My animated label does not work on this program


    Dear all,
    I have tried to make a simple egg timer for hearing disabled. (I had some problem with sound on RPi which I didn't want to deal with). However I decided to put an animated bell on the message by which a Bell is switching from left to right. The label it self works fine when I am running it as it is. But when I tried to integrate it in my main program my LED's are flashing fine but the animated label does not work. I am just puzzled. would somebody help me please?
    The other problem is when the program is finalized the last label stays there and I do not know the way to close it make it dis-appear. I cant submit any attachment but I have a couple of Icons in *.jpg at the same folder as the code. so it should work.
    Bellow is the code by which the animated label works fine:
    #!/usr/bin/env python
    from Tkinter import *
    from PIL import Image, ImageTk
    from time import sleep

    root=Tk()
    image1 =Image.open("Bell_R.jpg")
    icon1=ImageTk.PhotoImage(image1)
    image2 =Image.open("Bell_L.jpg")
    icon2=ImageTk.PhotoImage(image2)

    a=0
    while (a < 10) :
    a= a+1
    label= Label(image=icon1)
    label.image=icon1
    #label.text="Text 1"
    #label=Label(compound=RIGHT)
    label.grid(row=10, column=0)
    sleep(0.5)
    root.update()
    label= Label(image=icon2)
    label.image=icon2
    #label.text="Text 2"
    #label=Label(compound=RIGHT)
    label.grid(row=10, column=0)
    sleep(0.5)
    root.update()

    root.mainloop()
    ___________
    And here is the code which the above label is integrated, inside the while sentence LED flashes as it should but the label does not show the picture at all !!

    #!/usr/bin/env python
    #Note: This program runes only with IDLE2/Amir Amininejad
    from Tkinter import *
    from PIL import Image, ImageTk
    from time import sleep
    import sys
    import RPi.GPIO as GPIO

    GPIO.cleanup()
    # G PIO.setmode(GPIO.BCM) This is an alternativ mode of pin reference.
    GPIO.setmode(GPIO.BOARD)
    # Definition of the GPIO as input or output
    GPIO.setwarnings(False)
    GPIO.setup(11, GPIO.OUT)
    GPIO.setup(13, GPIO.OUT)
    GPIO.output(11,False)
    GPIO.output(13,False)

    def hide_me(event):
    event.widget.grid_forget()

    def LED_Blink(mn, ot, st) :
    #where mn is the max number of blinkin, ot=OnTime, st=SleepTime
    #tkMessageBox.showinfo("Time Out!", "DING DING DING!")
    GPIO.output(13,False)
    a=0
    alarm = Label(mainapp, text ="Time Out! DING DING DING!", fg="red", font=("Halvetica", 16))
    #alarm=Label()
    alarm.grid(row=10, column=0)
    alarm.bind('<Button-1>', hide_me)
    while (a < mn) :
    a= a+1
    #SleepTime= st
    GPIO.output(11,True)
    alarm= Label(image=icon1)
    alarm.image=icon1
    sleep(ot)
    mainapp.update()
    GPIO.output(11,False)
    alarm= Label(image=icon2)
    alarm.image=icon2
    sleep(st)
    mainapp.update()

    def start_timer() :
    #In final code the value should be 60000 insted of 1000
    GPIO.output(13,True)
    mainapp.after(scale.get() * 1000 )
    mainapp.bell ()
    LED_Blink(10, 0.5, 0.5)

    mainapp = Tk()
    image1 =Image.open("Bell_R.jpg")
    icon1=ImageTk.PhotoImage(image1)
    image2 =Image.open("Bell_L.jpg")
    icon2=ImageTk.PhotoImage(image2)

    mainapp.title("Visual Timer for hearing disabled by Amir Amininejad")
    #This defines the Lable
    minutes = Label(mainapp, text="Seconds:")
    minutes.grid(row=0, column=0)
    # This defines the slider
    scale = Scale(mainapp, from_=1, to=60, orient=HORIZONTAL, length=500)
    scale.grid(row=0,column=1)
    # Definition of a Button /AA
    button = Button(mainapp, text="Start Timer",command=start_timer)
    button.grid(row=1, column=1, pady=5, sticky=E)

    mainapp.mainloop()

    Thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    9
    Rep Power
    0

    Related to the code of animated label


    Hi again, while I am still awaiting to some feedback on this, I have realized that on inserting my code I have not used # sign for preservation of my indentation. sorry about that. I am still learning to proper using of this forum. However It does not seams my problem caused by this since it works but the code seams just to ignore anything related to the label but sets the GPIO pins to signal LED's of my proto attached to the RPi. It seam this is related to thread, multi processing or simply not utilizing the widgets in proper manner. How ever I am annoyed by not understanding what is going wrong. any hints there ????
  4. #3
  5. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,648
    Rep Power
    1945
    Please use code tags around your code to keep the space intention.
    [code ] [ /code] (remove space)

    I will also suggest you try to make some more air in you text.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    9
    Rep Power
    0

    Related to My Animated label......


    Hi Susan and all,
    Thanks for feedback, I have now tried to put some brackets around my code. and separated various logical part with more space. Hope this has helped to make it more readable. I hope I learn something from this.
    Please find re-edited code bellow:
    Br Amir and once again thanks for your effort.
    _________
    [#!/usr/bin/env python]
    [#Note: This program runes only with IDLE2]
    [from Tkinter import *]
    [from PIL import Image, ImageTk]
    [from time import sleep]
    [import sys]
    [import RPi.GPIO as GPIO]
    [GPIO.cleanup()]
    [# G PIO.setmode(GPIO.BCM) This is an alternativ mode of pin reference.]
    [GPIO.setmode(GPIO.BOARD)]
    [# Definition of the GPIO as input or output]
    [GPIO.setwarnings(False)]
    [GPIO.setup(11, GPIO.OUT)]
    [GPIO.setup(13, GPIO.OUT)]
    [GPIO.output(11,False)]
    [GPIO.output(13,False)]


    [def hide_me(event):]
    [ event.widget.grid_forget()]


    [def LED_Blink(mn, ot, st) :]
    [ #where mn is the max number of blinkings, ot=OnTime, st=SleepTime]
    [ GPIO.output(13,False)]
    [ a=0 ]
    [ alarm = Label(mainapp, text ="Time Out! DING DING DING!", fg="red", font=("Halvetica", 16))]
    [ alarm.grid(row=10, column=0)]
    [ alarm.bind('<Button-1>', hide_me)]


    [ while (a < mn) :]
    [ a= a+1]
    [ GPIO.output(11,True)]
    [ alarm= Label(image=icon1)]
    [ alarm.image=icon1]
    [ sleep(ot)]
    [ mainapp.update()]
    [ GPIO.output(11,False)]
    [ alarm= Label(image=icon2)]
    [ alarm.image=icon2]
    [ sleep(st)]
    [ mainapp.update() ]



    [def start_timer() :]
    [ #In final code the value should be 60000 insted of 1000]
    [ GPIO.output(13,True)]
    [ mainapp.after(scale.get() * 1000 )]
    [ mainapp.bell ()]
    [ LED_Blink(10, 0.5, 0.5)]


    [mainapp = Tk()]
    [image1 =Image.open("Bell_R.jpg")]
    [icon1=ImageTk.PhotoImage(image1)]
    [image2 =Image.open("Bell_L.jpg")]
    [icon2=ImageTk.PhotoImage(image2)]
    [mainapp.title("Visual Timer for hearing disabled")]


    [minutes = Label(mainapp, text="Seconds:")]
    [minutes.grid(row=0, column=0)]


    [# This defines the slider]
    [scale = Scale(mainapp, from_=1, to=60, orient=HORIZONTAL, ][length=500)]
    [scale.grid(row=0,column=1)]

    [ # Definition of a Button /AA]
    [button = Button(mainapp, text="Start Timer",command=start_timer)]
    [button.grid(row=1, column=1, pady=5, sticky=E)]

    [mainapp.mainloop()]
  8. #5
  9. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,648
    Rep Power
    1945
    You should read the sticky post, there the tags is also explain.
    The code tags should be around the code.
    E.g.
    [code ] Your code here [ /code]
    Remeve the space between [] and it will be like this:
    Code:
     Your code here
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    9
    Rep Power
    0

    Related to my Automated label


    OK thanks for advice, while I did not find out when to use
    Code:
     and when
    , but I learned that I shall only submit the related problem part. The problem part is given within the bellow function. What I do expect is
    while it is changing the LED light on and off with the same rate it changes the label icon alarm. but it jumps over this and only changes the GPIO signal on and off.
    [BTW: does this way of using [] looks ok?

    [def LED_Blink(mn, ot, st) :
    GPIO.output(13,False)
    a=0
    alarm = Label(mainapp, text ="Time Out! DING DING DING!", fg="red", font=("Halvetica", 16))
    alarm.grid(row=10, column=0)
    alarm.bind('<Button-1>', hide_me)


    while (a < mn) :
    a= a+1]
    GPIO.output(11,True)
    alarm= Label(image=icon1)
    alarm.image=icon1
    sleep(ot)
    mainapp.update()
    GPIO.output(11,False)
    alarm= Label(image=icon2)
    alarm.image=icon2
    sleep(st)
    mainapp.update()]
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    9
    Rep Power
    0

    Related to My Animated Label.....


    [/def LED_Blink(mn, ot, st) :]
    [/ GPIO.output(13,False)]
    [/ a=0]
    [/ alarm = Label(mainapp, text ="Time Out! DING DING "][/ DING!", fg="red", font=("Halvetica", 16))]
    [/ alarm.grid(row=10, column=0)]
    [/ alarm.bind('<Button-1>', hide_me)]


    [/ while (a < mn) :]
    [/ a= a+1]
    [/ GPIO.output(11,True)]
    [/ alarm= Label(image=icon1)]
    [/ alarm.image=icon1]
    [/ sleep(ot)]
    [/ mainapp.update()]
    [/ GPIO.output(11,False)]
    [/ alarm= Label(image=icon2)]
    [/ alarm.image=icon2]
    [/ sleep(st)]
    [/mainapp.update()]
  14. #8
  15. Lord of the Dance
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Oct 2003
    Posts
    3,648
    Rep Power
    1945
    Start with
    [code ]

    Type you code (copy/past) in here

    then end with
    [ /code]

    You can see in your own post where you have it correct:
    Code:
    and when
  16. #9
  17. No Profile Picture
    Permanently Banned
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    4
    Rep Power
    0
    nice pot bro. thanks for sharing this information.

IMN logo majestic logo threadwatch logo seochat tools logo