[Tutor] Clock in tkinter?

Wayne Werner waynejwerner at gmail.com
Tue Nov 15 22:14:11 CET 2011


On Tue, Nov 15, 2011 at 2:00 PM, Mic <o0MB0o at hotmail.se> wrote:

>   Hi!
> I am new to programming and I hop this question isn’t stupid.
>

Welcome!


>  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 *
> import time
>
> class Window(Frame):
>     def __init__(self,master):
>         super(Window,self).__init__(master)
>         self.grid()
>         self.create_widgets()
>
>     def create_widgets(self):
>         self.test_button=Button(self, text="Hi")
>         self.test_button.grid(row=0,column=0)
>
> root=Tk()
> root.title("Test")
> root.geometry("200x200")
> app=Window(root)
> root.mainloop()
>

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
>>> help(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.

HTH,
Wayne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111115/de15e754/attachment.html>


More information about the Tutor mailing list