<HTML><HEAD></HEAD>
<BODY dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV> </DIV>
<DIV
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none">
<DIV style="FONT: 10pt tahoma">
<DIV><FONT size=3 face=Calibri></FONT></DIV>
<DIV
style="FONT-STYLE: normal; DISPLAY: inline; FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: small; FONT-WEIGHT: normal; TEXT-DECORATION: none"></DIV></DIV>
<DIV class=gmail_quote>
<DIV>If you're going to put a function inside your class (since you're using
self in there, I'm sure that's what you meant to do), you should change it
to:</DIV>
<DIV> </DIV>
<DIV> def change_value_the_time(self):</DIV>
<DIV> </DIV>
<DIV>and call it with</DIV>
<DIV> </DIV>
<DIV> self.display_time.after(20,
self.change_value_the_time)</DIV>
<DIV> </DIV>
<DIV>But your program also has unnecessary code. First, since you have a class
then instead of using a global, you should simply declare `self.the_time = ''`
in your __init__ for your class.</DIV>
<DIV> </DIV>
<DIV>Personally, I would have written the function more like this:</DIV>
<DIV> </DIV>
<DIV>def update_time(self):</DIV>
<DIV> self.display_time.config(text=time.strftime('%H:%M:%S'),
font='40')<BR> self.after(20, self.update_time)</DIV>
<DIV> </DIV>
<DIV>Then at the end of my __init__ function I would call
self.update_time()</DIV>
<DIV> </DIV>
<DIV>I'm not sure how that will work with your current setup, though.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>-------------------------------------------------------------------------------------------------------------------------------------</DIV>
<DIV class=gmail_quote>
<DIV> </DIV>
<DIV>I have now worked to stop using the global scope and instead put my prior
global variable into</DIV>
<DIV>the constructor in the class. I believe that I have managed to do that
now.</DIV>
<DIV> </DIV>
<DIV>Do you believe that this is correctly done?</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>#Trying putting the_time'' in constructor instead of</DIV>
<DIV>#putting it in the global scope to shorten code.</DIV>
<DIV> </DIV>
<DIV>from tkinter import*</DIV>
<DIV>import time</DIV>
<DIV>import os</DIV>
<DIV> </DIV>
<DIV>class Window(Frame):</DIV>
<DIV> def __init__(self,master):</DIV>
<DIV> super
(Window,self).__init__(master)</DIV>
<DIV> self.grid()</DIV>
<DIV> self.the_time=''</DIV>
<DIV> self.create_widgets()</DIV>
<DIV> self.update_time()</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> def create_widgets(self):</DIV>
<DIV> </DIV>
<DIV> #Create a hello Button:</DIV>
<DIV> self.hellobttn=Button(self,
text="Hey")</DIV>
<DIV> self.hellobttn.grid(row=0,
column=1)</DIV>
<DIV> </DIV>
<DIV> #Create a label that displays
time.</DIV>
<DIV> self.display_time=Label(self,
text=self.the_time)</DIV>
<DIV> self.display_time.grid(row=1,
column=1)</DIV>
<DIV> </DIV>
<DIV> def update_time(self):</DIV>
<DIV>
self.display_time.config(text=time.strftime('%H:%M:%S'), font='40')</DIV>
<DIV> self.after(20, self.update_time)</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>root=Tk()</DIV>
<DIV>root.title("Test")</DIV>
<DIV>root.geometry("200x200")</DIV>
<DIV>app=Window(root)</DIV>
<DIV>root.mainloop() </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>I get no error while doing this, and the program works fine.</DIV>
<DIV> </DIV>
<DIV>I have another question.</DIV>
<DIV> </DIV>
<DIV>Say that I have a class and I want to make 100 objects. </DIV>
<DIV>Then it could look like this:</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>#How to shorten this?</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>#Create the class.</DIV>
<DIV>class Chairs(object):</DIV>
<DIV> def __init__(self, age, weight):</DIV>
<DIV> self.age=age</DIV>
<DIV> self.weight=weight</DIV>
<DIV> </DIV>
<DIV> def __str__(self):</DIV>
<DIV> </DIV>
<DIV> rep=self.age+self.weight</DIV>
<DIV> return rep</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>#Create the objects</DIV>
<DIV>chair1=Chairs("10","20")</DIV>
<DIV>chair2=Chairs("10","20")</DIV>
<DIV>chair3=Chairs("10","20")</DIV>
<DIV>chair4=Chairs("10","20")</DIV>
<DIV>chair5=Chairs("10","20")</DIV>
<DIV>chair6=Chairs("10","20")</DIV>
<DIV>chair7=Chairs("10","20")</DIV>
<DIV>chair8=Chairs("10","20")</DIV>
<DIV>chair9=Chairs("10","20")</DIV>
<DIV>#And so on</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>How do I shorten this? I have thought of using a for sling. I have looked
in my programming</DIV>
<DIV>book and on the internet, but I dont know how to make this shorter. The
arguements (10, 20)</DIV>
<DIV>should be the same for every object, which should make it easier than if
they were different each time?</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Right now, it feels like a lot of my code in my other programs could be
made dramatically shorter.</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Thanks!</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV></DIV>
<DIV> </DIV>
<BLOCKQUOTE
style="BORDER-LEFT: #ccc 1px solid; MARGIN: 0px 0px 0px 0.8ex; PADDING-LEFT: 1ex"
class=gmail_quote>
<DIV dir=ltr>
<DIV dir=ltr>
<DIV style="FONT-FAMILY: 'Calibri'; COLOR: #000000; FONT-SIZE: 12pt">
<DIV class=im></DIV>
<DIV> </DIV></DIV></DIV></DIV></BLOCKQUOTE></DIV></DIV></DIV></DIV></BODY></HTML>