How to have maximum characters in a text widget
<p>I do not understand how to have a maximum of 4 charachters allowed in the text widget. At the moment, when the buttons are pressed an infinite amount of numbers are shown in the text widget. Example: 123456 but i only want 1234 for this case to be shown.</p>

<p>Also if possible how do you change the size of the window that contains all the widgets as at the moment, the window is much larger than the widgets whereas i just want it to be the same length. Images to the sizing are shown below:</p>

<p><a href="http://i.stack.imgur.com/RsBrz.png" rel="nofollow">Original</a></p>

<p><a href="http://i.stack.imgur.com/U2mg8.png" rel="nofollow">What i want the window size to be</a></p>

<p>Based on "how to have a maximum of 4 charachters allowed": you need to have a validation in your program:<br/>
Assuming that you only want integer numbers in the range of [1-4] (1, 2, 3, 4):</p>

<pre><code>from tkinter import *
root = Tk()

def valFunc(txt):
    if len(txt) &lt;= 4:
        try:
            txt = int(txt)
            return True
        except:
            return False
    else:
        return False

vcmd = root.register(valFunc)

e = Entry(root, validate="key", validatecommand=(vcmd, "%P"))
e.pack()
</code></pre>

<p>And for the window size you need to use a <code>geometry</code> method for your window.</p>

python tkinter