0

I just started learning development for raspberry pi. I want to develop an application in TKinter which shows a count down from current date time to a fixed end date time. Where can I find sample source codes related to this. Also what are the other options which I can use to develop GUI based applications for raspberry pi.

Vinita
  • 95
  • 1
  • 3
  • 9

2 Answers2

0

There is a timer implemented here : How to create a timer using tkinter?. You should be able to modify it to match your needs.

Concerning your second question, I would advise to stick with Tkinter : it is a simple and lightweight GUI framework, yet quite powerful. EasyGUI is another simple framework, but I find it a bit too restrictive. At last, depending on your distribution, you can always bind your GUI to the OS desktop env : PyGnome, PyKDE, ... (Just avoid Qt and WxWidgets which are memory-monsters).

A list here : http://wiki.python.org/moin/GuiProgramming

Community
  • 1
  • 1
lucasg
  • 10,734
  • 4
  • 35
  • 57
0

Here ya go.

import Tkinter as TK
import datetime

class countdown:
    def __init__(self, master, time):   # time in mm/dd/yy hh:mm:ss format
        self.master = master
        self.frame = TK.Frame(self.master)
        self.targetTime = datetime.datetime.strptime(time, "%m/%d/%y %H:%M:%S")
        self.timeRemainingLabel = TK.Label(self.frame)
        self.startButton = TK.Button(self.frame, text="Start countdown", command=lambda:self.master.after(1000, self.update))
        self.endTimeLabel = TK.Label(self.frame, text="Target time in mm/dd/yy hh:mm:ss format:")
        self.endTimeEntry = TK.Entry(self.frame)
        self.endTimeEntry.insert(0, time)
        self.frame.grid()
        self.timeRemainingLabel.grid(row=1,column=1, columnspan=3)
        self.startButton.grid(row=2, column=1, rowspan=2)
        self.endTimeLabel.grid(row=2, column=2)
        self.endTimeEntry.grid(row=3, column=2)

    def update(self):
        remaining = self.targetTime-datetime.datetime.now()
        daysRemaining = remaining.days
        hoursRemaining = int(remaining.seconds) / 3600
        minutesRemaining = int(remaining.seconds % 3600) / 60
        secondsRemaining = int(remaining.seconds % 60)
        self.timeRemainingLabel.config(text="Time remaining until {targetTime}:\n*** {days} days {hours} hrs {minutes} min {seconds} sec ***".format(targetTime=datetime.datetime.strptime(self.endTimeEntry.get(), "%m/%d/%y %H:%M:%S"), days=daysRemaining, hours=hoursRemaining, minutes=minutesRemaining, seconds=secondsRemaining))
        self.master.after(1000, self.update)

root = TK.Tk()
c = countdown(root, "08/31/13 01:01:01")
root.mainloop()

Image:

enter image description here

Brionius
  • 13,858
  • 3
  • 38
  • 49