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

    Join Date
    Oct 2013
    Posts
    9
    Rep Power
    0

    I need help related to Runing sequence of Python.


    Dear all,
    I am new in Python programming. But in order to learn Python I have acquired a RaspberryPi running Debian Linux Os. and using IDlE2 and integrating Tkinter- I have made a simple Egg timer by which after timer expiring I am attempting to alert by writing Ding, Ding, Ding on a label and after that I start a loop by which I flash an LED on the GPIO port of Raspberry.
    Every thing works fine but the sequence !!!
    It is important to write the label and then start to blink the LED.
    I have tried a couple of attempts even I have tried to re structure, the occurrence of Label first and Loop next but without much of luck. The case is after timer expired, LED starts to flash after it is done, then the Ding,Ding, Ding shows. while this is improper. Preferably these should happened simultaneously.
    I will appreciate any help on this.
    Br and thanks in Advance Amigo
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    635
    Rep Power
    66
    We do need to see your code or else we have to learn mind reading.
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    9
    Rep Power
    0

    Re: I need help related to Runing Sequence of Python.


    Originally Posted by Dietrich
    We do need to see your code or else we have to learn mind reading.
    Thanks for your replay Dietrich,
    I am sorry to not adding my code. But Now it is given bellow. (Sorry I could not find a way to give it as an attachment).
    BTW: I liked your joke about OCT31=DEC25

    #!/usr/bin/env python
    #Note: This program runes only with IDLE2

    from Tkinter import *
    import sys
    import tkMessageBox
    import RPi.GPIO as GPIO
    from time import sleep
    GPIO.cleanup()
    # GPIO.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 L_write():
    alarm = Label(root, text ="Time Out! DING DING DING!", fg="red", font=("Halvetica", 16))
    alarm.grid(row=10, column=0)
    alarm.state =1

    def show_alert(mn, ot, st) :
    #where mn is the max number of blinkin, ot=OnTime, st=SleepTime

    GPIO.output(13,False)
    a=0
    L_write()
    while (a < mn) :
    a= a+1
    SleepTime=st
    GPIO.output(11,True)
    sleep(ot)
    GPIO.output(11,False)
    sleep(st)


    def start_timer() :
    #In final code the value should be 60000 insted of 1000
    GPIO.output(13,True)
    root.after(scale.get() * 1000 )
    root.bell ()
    show_alert(5, 0.2, 0.6)

    root = Tk()
    root.title("Visual Timer for hearing disabled ")
    #This defines the Lable
    minutes = Label(root, text="Seconds:")
    minutes.grid(row=0, column=0)
    # This defines the slider
    scale = Scale(root, from_=1, to=60, orient=HORIZONTAL, length=500)
    scale.grid(row=0,column=1)
    # Definition of a Button /AA
    button = Button(root, text="Start Timer",command=start_timer)
    button.grid(row=1, column=1, pady=5, sticky=E)
    root.mainloop()
  6. #4
  7. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    635
    Rep Power
    66
    Here is an example of the use of Tkinter's update() function after sleep() ...
    Code:
    # countdown to New Year using Tkinter
    # use update() after sleep()
    
    from Tkinter import *
    import time 
    
    def countDown():
        '''start countdown 10 seconds before new year starts'''
        lbl.config(bg='yellow')
        for k in range(10, -1, -1):
            lbl["text"] = k
            time.sleep(1)
            root.update()  # Tk needs this after sleep()
        lbl.config(bg='red')
        lbl["text"] = "Happy new year!"
        
    root = Tk()
    lbl = Label()
    lbl.pack(fill=BOTH, expand=1)
    countDown()
    root.mainloop()
    Last edited by Dietrich; October 18th, 2013 at 10:40 AM.
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    9
    Rep Power
    0

    I need help related to Runing sequence of Python.


    Dear Dietrich,
    Thanks a lot for the valuable feedback,
    I can inform that I have now adopted this "update" command and this has resolved my problem. Now I am in the situation that I want to get ride of the label "Ding, Ding. Ding" after it has served its purposes.
    So I am intended to make it invisible, destroy it, delete it or some how make it out of site and make the timer ready for new settings. I have been studying a number of examples where they utilize an event definition and binding it to the label for clicking on it or such. But I wonder if there is any possibilities to get this label to be invisible after the timer has expired or when the number of led blink is reached to the limit. (for instance in my code above, using an 'if' statement for when a== mn then hide the label ).
    Br and once more thanks in advance
    Amigo

IMN logo majestic logo threadwatch logo seochat tools logo