Hi,
Could anybody help me in displaying the time at some Corner of the dialog,when the application is running.
Display time on the dialog for the entire process.
Thanks
PSB
8 31636
Hi,
Could anybody help me in displaying the time at some Corner of the dialog,when the application is running.
Display time on the dialog for the entire process.
Thanks
PSB
- # use Tkinter to show a digital clock
-
# tested with Python24 vegaseat 10sep2006
-
-
from Tkinter import *
-
import time
-
-
root = Tk()
-
time1 = ''
-
clock = Label(root, font=('times', 20, 'bold'), bg='green')
-
clock.pack(fill=BOTH, expand=1)
-
-
def tick():
-
global time1
-
# get the current local time from the PC
-
time2 = time.strftime('%H:%M:%S')
-
# if time string has changed, update it
-
if time2 != time1:
-
time1 = time2
-
clock.config(text=time2)
-
# calls itself every 200 milliseconds
-
# to update the time display as needed
-
# could use >200 ms, but display gets jerky
-
clock.after(200, tick)
-
-
tick()
-
root.mainloop( )
Thanks for the reply.
Is it possible to display the duration of time taken for executing the application?
Say ,it should start with 00:00:00, and display the time taken for the aplication.
1) start time
2) Mainn function call
3) End time
In between start and end time ,the time duration has to be displayed.Any suggestions on this.
-PSB
Thanks for the reply.
Is it possible to display the duration of time taken for executing the application?
Say ,it should start with 00:00:00, and display the time taken for the aplication.
1) start time
2) Mainn function call
3) End time
In between start and end time ,the time duration has to be displayed.Any suggestions on this.
-PSB
47 seconds flat: -
>>> import datetime as dt
-
>>> import time
-
>>> t = time.localtime()
-
>>> t
-
(2007, 4, 8, 2, 11, 19, 6, 98, 1)
-
>>> zeroTime = dt.timedelta(hours=t[3], minutes=t[4], seconds=t[5])
-
>>> now = dt.datetime(1, 1, 1).now()
-
>>> now - zeroTime
-
datetime.datetime(2007, 4, 8, 0, 0, 47, 324000)
-
>>>
As the application is running ,I would like to display the time duration taken dynamically on the dialog.
Say the appliation started with 00:00:00,as the application started processing the execution then the time display should show the following
00:00:01
00:00:02
......
00:00:47
Every second increment has to be shown in the display at particular location
Thanks
PSB
As the application is running ,I would like to display the time duration taken dynamically on the dialog.
Say the appliation started with 00:00:00,as the application started processing the execution then the time display should show the following
00:00:01
00:00:02
......
00:00:47
Every second increment has to be shown in the display at particular location
Thanks
PSB
Sorry, I left this out: -
>>> elapsedTime = now - zeroTime
-
>>> elapsedTime.strftime('%H:%M:%S')
-
'10:29:09'
-
>>>
All the pieces are now here (10 hours, 29 minutes and 9 seconds later).
Sorry, I left this out: -
>>> elapsedTime = now - zeroTime
-
>>> elapsedTime.strftime('%H:%M:%S')
-
'10:29:09'
-
>>>
All the pieces are now here (10 hours, 29 minutes and 9 seconds later).
I've put all the pieces together into a subclass of Label. Simple add this widget to you layout as you would a Tk.Label. Time starts when the widget is created. - from Tkinter import Tk, Label, BOTH
-
import time
-
import datetime as dt
-
-
-
-
class ElapsedTimeClock(Label):
-
def __init__(self, parent, *args, **kwargs):
-
Label.__init__(self, parent, *args, **kwargs)
-
self.lastTime = ""
-
t = time.localtime()
-
self.zeroTime = dt.timedelta(hours=t[3], minutes=t[4], seconds=t[5])
-
self.tick()
-
-
def tick(self):
-
# get the current local time from the PC
-
now = dt.datetime(1, 1, 1).now()
-
elapsedTime = now - self.zeroTime
-
time2 = elapsedTime.strftime('%H:%M:%S')
-
# if time string has changed, update it
-
if time2 != self.lastTime:
-
self.lastTime = time2
-
self.config(text=time2)
-
# calls itself every 200 milliseconds
-
# to update the time display as needed
-
# could use >200 ms, but display gets jerky
-
self.after(200, self.tick)
-
-
-
if __name__ == "__main__":
-
root = Tk()
-
clock = ElapsedTimeClock(root, font=('times', 20, 'bold'), bg='green')
-
clock.pack(fill=BOTH, expand=1)
-
root.mainloop()
-
-
Thanks Barton,
But where should I have to call my application/main method ,where the time starts before the method call,and it should keep showing the time in mins/secs (some times hrs) untill the method has been executed and come out of the method and display the final time duration .
It should stop showing the time ,once it comes out of the main method of the application/ application executed.
-PSB
Thanks Barton,
But where should I have to call my application/main method ,where the time starts before the method call,and it should keep showing the time in mins/secs (some times hrs) untill the method has been executed and come out of the method and display the final time duration .
It should stop showing the time ,once it comes out of the main method of the application/ application executed.
-PSB
My thinking was that what ever method was being timed would own the GUI.
If that's not the case, remove
and call
when you want to start it. You can add a flag to turn the timer on and off in tick().
I'd also add GetElapsedTime() and ResetElapsedTime().
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Josh |
last post by:
Caution, newbie approaching...
I'm trying to come up with a very simple Tkinter test application that
consists of a window with a drop-down menu bar at the top and a grid
of colored rectangles...
|
by: midtoad |
last post by:
I'm trying to display a GIF image in a label as the central area to a
Tkinter GUI. The image does not appear, though a space is made for it.
Why is this so?
I notice that I can display a GIF...
|
by: Jeffrey Barish |
last post by:
Is there a way to fill the values in an OptionMenu dynamically? I need
something like the add_command method from Menu. Is there a better way
to implement a pull-down list?
--
Jeffrey Barish
|
by: Donald Xie |
last post by:
Hi,
I noticed an interesting effect when working with controls that are
dynamically loaded. For instance, on a web form with a PlaceHolder control
named ImageHolder, I dynamically add an image...
|
by: npaulus |
last post by:
Hi,
I am trying to dynamically add user controls on to my web form but for
some reason my form isnt displaying the user control.
form1.cs:
using System;
using System.Drawing;
using...
|
by: Dustan |
last post by:
Nobody answered last time. I guess they wanted me to give it a shot.
Well, here is how I download the image (it's a class method):
def download_image(self):...
|
by: sj |
last post by:
I am just learning to use Tkinter and am having problems displaying image
files. I am able to display an image using tutorials (such as
http://www.daniweb.com/code/snippet296.html) But when I try...
|
by: MartinRinehart |
last post by:
Everything I've read about Tkinter says you create your window and
then call its mainloop() method. But that's not really true. This is
enough to launch a default window from the console:
...
|
by: viv1tyagi |
last post by:
Hi everyone ! ! !
I'm just a month old in the world of Python and trying to develop an
application using Tkinter in which a new window pops out on a
particular button press.The code for this new...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
| |