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.
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()
(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.
(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 :/