Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Clock Program
#1
For my current assignment, I had to make a clock program:

class clock():
    import Tkinter as tk
    import time
 
    def update_timeText():
        current = time.strftime("%H:%M:%S")
        timeText.configure(text=current)
        root.after(1000, update_timeText)
 
    root = tk.Tk()
    root.wm_title("Clock")
 
    timeText = tk.Label(root, text="", font=("Helvetica", 150))
    timeText.pack()
    update_timeText()
    root.mainloop()
It says I also must prompt the user to enter data for each of the object's data attributes, store the data in the object and then use the object's accessor methods to retrieve it and display it on the screen. Can someone please remind me how to do that please? Also, as a reminder, I use 2.x, not 3.x.
Reply
#2
Why do you prefer Python 2.x ?

Here is a Python 3.x version:

#!/usr/bin/python3
import tkinter as tk
import time

class Clock():
    def update_timeText(self):
        current = time.strftime("%H:%M:%S")
        timeText.configure(text=current)
        root.after(1000, self.update_timeText)

root = tk.Tk()
root.wm_title("Clock")

timeText = tk.Label(root, text="", font=("Helvetica", 150))
timeText.pack()
clock = Clock()
clock.update_timeText()

root.mainloop()
Reply
#3
(Nov-18-2017, 06:33 AM)heiner55 Wrote: Why do you prefer Python 2.x ?

Perhaps that is the only version available on the schools computers or perhaps it is a requirement set by the instructor. Regardless, it is up to us to honor that requirement. In addition, in the 'Homework' forum, we ask that members refrain from writing the actual code for the student as it may impact their grade and is unfair to their fellow students. 

That said, @heiner55 is correct in pointing out (whether using Python 2 or 3), imports should be at the top of your file, not buried within the code. Also your indentation is incorrect.

As to your question, it is helpful to us if you tell us what this requirement  prompt the user to enter data for each of the object's data attributes, store the data in the object and then use the object's accessor methods to retrieve it and display it on the screen. means to you, in your own words. In other words, to you, what is the "object", what are it's "attributes" and what are it's "accessor methods".  If your thinking is wrong, we can help correct that thinking, if your thinking is right, we can guide you on how to implement it. As it stands, since your code does not show any attempt at addressing this requirement, we are very limited in what we can do for you.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply
#4
(Nov-18-2017, 06:33 AM)heiner55 Wrote: Why do you prefer Python 2.x ?

Here is a Python 3.x version:

#!/usr/bin/python3
import tkinter as tk
import time

class Clock():
    def update_timeText(self):
        current = time.strftime("%H:%M:%S")
        timeText.configure(text=current)
        root.after(1000, self.update_timeText)

root = tk.Tk()
root.wm_title("Clock")

timeText = tk.Label(root, text="", font=("Helvetica", 150))
timeText.pack()
clock = Clock()
clock.update_timeText()

root.mainloop()

I use it simply because that's what my teacher is having my class use. He said it's because not many people use 3.x, but it seems like the majority of people on this site use 3.x so I think he might be wrong :/
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020