How do i output a single digit as a double digit in python 2.7
Question: I just started to play around with python and decided to make a random number
generator for my lotto numbers and so far so good it works, and even got it to
work in Tkinter.

But i can't seem to figure out where and how to format the output so that it
displays some nicely formatted rows of lists.

Any help or suggestions would be greatly appreciated.

Hugo

The script I got working so far in python 2.7

    
    
    import random
    from Tkinter import *
    import Tkinter as ttk
    
    
    def f():
        my_list = []
        while len(my_list) < 6:
            new_number = random.randrange(45) + 1
            if new_number in my_list:
                continue
            my_list.append(new_number)
            winners = sorted(my_list)
            if len(my_list) == 6:
                return winners
    
    
    def genereer(*args):
        x = int(getal.get())
        my_list2 = []
        if x < 11:
            while len(my_list2) < x:
                f()
                my_list2.append(f())
        for item in my_list2:
            ttk.Label(mainframe, text=item).grid(column=0, sticky=W)
    
    
    root = Tk()
    root.title("Lotto nummers generator.")
    
    mainframe = ttk.Frame(root)
    mainframe.grid(column=0, row=0, sticky=(N, W, E, S))
    mainframe.columnconfigure(1, weight=1)
    mainframe.rowconfigure(1, weight=1)
    
    getal = StringVar()
    
    ttk.Label(mainframe,
    text="Hoeveel rijtjes will je spelen? (max 10)").grid(column=0, row=1,sticky=W)
    
    getal_entry = ttk.Entry(mainframe, width=3, textvariable=getal)
    getal_entry.grid(column=1, row=1, sticky=W)
    
    ttk.Button(mainframe, text="Genereer", command=genereer).grid(column=3,
    row=1, sticky=W)
    
    getal_entry.focus()
    root.bind("<Return>", genereer)
    
    root.mainloop()
    


Answer: I was never using TKinter, but I tried sth like that:

    
    
    ...
    
    MAX_VALUE = 46
    NUMS_PER_SAMPLE = 6
    POOL = range(1, MAX_VALUE+1)
    
    
    def f():
        return sorted(random.sample(POOL, NUMS_PER_SAMPLE))
    
    
    def genereer(*args):
        x = int(getal.get())
    
        if x > 10:
            return
    
        for x in range(x):
            for i, item in enumerate(f()):
                ttk.Label(mainframe, text=item).grid(row=x+2, column=i, sticky=E)
    
    ...
    

It's not perfect, because it uses the same grid as initial label and button,
but from that point you should be able to adjust it to your needs. I also
simplified your code by taking advantage of standard library
([`random.sample`](http://docs.python.org/2/library/random.html#random.sample)
is your friend).

