kriwil
5/28/2015 - 12:56 AM

rd.py

import random

from Tkinter import *


class Application(Frame):

    wait = 50

    def __init__(self, master=None):
        Frame.__init__(self, master)
        self.master = master
        self.pack()
        self.createWidgets()
        master.after(self.wait, self.animate)

    def createWidgets(self):
        self.first = Label(self)
        self.first["text"] = "0"
        self.first["height"] = 10
        self.first["width"] = 20
        self.first["font"] = ("sans-serif", 30)
        self.first.pack({"side": "left"})

    def update_first(self):
        number = random.randint(0, 9)
        self.first["text"] = str(number)

    def animate(self):
        self.update_first()
        self.master.after(self.wait, self.animate)


root = Tk()
app = Application(master=root)
app.mainloop()
root.destroy()