#!/usr/bin/env python3 from tkinter import * root = Tk() class GrowLabel(Label): def __init__(self, master): Label.__init__(self, master) self.counter = 12 self.config(text=str(self.counter), fg="blue", font=("verdana", self.counter, "bold")) self.pack() button = Button(self.master, text="Stop", command=self.master.destroy) button.pack() def count(self): self.counter += 1 self.config(text=str(self.counter), fg="blue", font=("verdana", self.counter, "bold")) self.after(1000, self.count) label = GrowLabel(root) label.count() root.mainloop()
Nouns are best for class names instead of verbs.
GrowLabel sounds like an action.
GrowingLabel would sound like a label that grows.
Related to this,
count method on a
GrowingLabel object doesn't sound natural.
The fact that you implement the growing effect using a count should be an internal detail,
and not revealed to users of the class.
The important point is that the label can grow,
not how it does it.
So, renaming the method to
grow() would be more natural.
Calling super-class methods
Since you are in Python 3,
it would be better to call the super constructor of
GrowLabel like this:
If that doesn't work somehow (I don't have
tkinter to try),
then try this instead:
See more details in this related discussion.
Avoid wildcard imports
Don't use wildcard imports like this:
from tkinter import *
Quoting from PEP8:
Wildcard imports (from import *) should be avoided, as they make it unclear which names are present in the namespace, confusing both readers and many automated tools.
I guess you do this because you're using many classes from this module. A better way would be to do like this:
import tkinter as tk
And then you can prefix the classes you need with
tk., like this:
root = tk.Tk()