[Tutor] Clock in tkinter?
o0MB0o at hotmail.se
Wed Nov 16 16:28:57 CET 2011
It is no homework, in fact am I working ahead of class. I have now, after five minutes thinking, solved my problem, but a new problem has risen.
But to begin with, here is how I solved the problem:
from tkinter import*
#Create a hello button:
#Create a label that displays time:
newtime = time.strftime('%H:%M:%S')
if newtime != the_time:
I found some help on the internet about making a clock, although I had to modify a lot of the code to fit my own code and window.
Now to my next question. Say that I want a text “Hi, how are you?” to be printed when the time passes 15:00:00 each day. How do I do that?
At first I thought that I could just write an if statement. Like:
print (“Hi, how are you?”)
But it is obviously not working.
Thank you for your help! Another question, am I supposed to add tutor at email@example.com; as copy? You did that, right?
From: Wayne Werner
Sent: Tuesday, November 15, 2011 10:14 PM
Cc: tutor at python.org
Subject: Re: [Tutor] Clock in tkinter?
On Tue, Nov 15, 2011 at 2:00 PM, Mic <o0MB0o at hotmail.se> wrote:
I am new to programming and I hop this question isn’t stupid.
I am making a small GUI program. It is supposed to have a button and a clock in it that displays the same time as it is according to the computer.
So as far as I am concerned both the clock and the are supposed to be widgets?
Is this a homework assignment, or just something that you're doing for fun? It seems homework-ish. We don't mind pointing you in the right direction on homework assignments, but we definitely won't do it for you.
So how do I add this clock as a widget placed next to the button?
Tkinter doesn't have a native clock widget, so if you want to make a clock you need to roll your own.
Here is the code I have written so far, that only displays a GUI window, and a button:
from tkinter import *
Giving us code (especially such a small amount) is exactly the right thing to do when you ask a question - it shows that you've tried something, and if it's broken it usually shows why it's broken.
You can add text to the Label widget - and you can change the text on that widget.
You're already importing the time module - for more information about what it contains, you can run the interactive interpreter and do this:
>>> import time
Or you can look online for the commands that might help you.
If you get stuck, let us know what you're doing and where you're stuck at.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Tutor