473,386 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

how to display clock?

I'm still working on the bpm counter.

I need to have at least 2 displays that are not static. One would be a
clock/running time and the other would should the current beat count.

How would I do this in Tkinter? I was thinkning of canvas-text, but
there must be a widget for doing this kind of display. I'm a bit lost
and would appreciate some help.
Jul 18 '05 #1
1 3568
Agency wrote:
I'm still working on the bpm counter.

I need to have at least 2 displays that are not static. One would be a
clock/running time and the other would should the current beat count.

How would I do this in Tkinter? I was thinkning of canvas-text, but
there must be a widget for doing this kind of display. I'm a bit lost
and would appreciate some help.


What's your exact problem here? Is it a problem with the display itself or the
fact that it is not static? As for the display itself, a simple label should be
enough if you use its textvariable option to make changes to its text easier. If
the problem lies in the dynamicity, here is a simple example showing how to
display two dynamic displays at the same time using only Python and Tkinter:

--clock-n-beat.py-------------------------
from Tkinter import *

## Main window
root = Tk()

## The tempo to use for the beat
tempo = 90

## Tkinter variables for clock and beat
clockVar = IntVar()
beatVar = IntVar()
## First beat in measure is 1
beatVar.set(1)

## This function will be called periodically to update the clock
def clockPulse():
## Increase clock value
clockVar.set(1 + clockVar.get())
## Call again current function in 1000 micro-seconds = 1 second
root.after(1000, clockPulse)

## This function will be called periodically to update the beat
def beatPulse():
## Increase beat
beat = beatVar.get() + 1
## Assuming a 4/4 measure, wrap beat if it's too high
if beat > 4:
beatVar.set(1)
else:
beatVar.set(beat)
## Call again this function in the correct amount of micro-seconds
## depending on tempo
root.after(int(60000.0 / tempo), beatPulse)

## Title and display for clock
Label(root, text="Clock:").grid(row=0, column=0, sticky=W)
Label(root, textvariable=clockVar).grid(row=0, column=1, sticky=W)

## Title and display for beat
Label(root, text="Beat:").grid(row=1, column=0, sticky=W)
Label(root, textvariable=beatVar).grid(row=1, column=1, sticky=W)

## Quit button
Button(root, command=root.quit, text='Quit').grid(row=2, column=0, columnspan=2)

## Make sure the first calls to the functions updating the clock and beat
## will be made
root.after(1000, clockPulse)
root.after(int(60000.0 / tempo), beatPulse)

## Go!
root.mainloop()
------------------------------------------

HTH
--
- Eric Brunel <eric dot brunel at pragmadev dot com> -
PragmaDev : Real Time Software Development Tools - http://www.pragmadev.com

Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: James Harriman | last post by:
Hi, I need to be able to measure a time interval in milliseconds on a windows machine. I have tried using time.clock() but it appears to measure time in seconds...Is there a way to measure time...
3
by: Bei | last post by:
I have variable, say "total". It can be an integer or floating number. No matter what value it stores (5 or 5.1 or 5.24), when I display it, is there a way I can make it display it with fixed 2...
8
by: Monty | last post by:
Let's say you provide an online service from 7:00AM to 6:00PM Eastern Time (daylight time in the summer). Is there way of showing these hours of availability on a web page in the user's local...
7
by: JCO | last post by:
How do you do this. I would like for it to be as dynamic as each page refresh. Thanks
33
by: Pushkar Pradhan | last post by:
I'm using clock() to time parts of my code e.g. clk1 = clock(); /* code */ clk2 = clock(); /* calculate time in secs */ ...... clk1 = clock(); /* code */ clk2 = clock();
2
by: Daniel | last post by:
Hi, Display clock in window form is easy..in web page?? Helps will be appreciated ..thank you. Best regards, Ocurnos
2
by: libsfan01 | last post by:
Hi all! I have this javascript timer which counts down the number of secs that i put in and then then redirects my page, what i want to know is how to i modify the code so that i can input the...
54
by: CoreyWhite | last post by:
The following experiment is a demonstration of TIME TRAVEL. When writing this program, and testing it out I found that sometimes the program would engage itself in time travel but other times it...
0
by: adubra | last post by:
Hi there, I am using a device context (DC) and a buffer to successfully draw to screen. However, when I update the DC at very high frame rate and drag the frame containing the image very quickly...
0
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,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
jinu1996
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.