python - How to have maximum characters in a text widget -


i not understand how have maximum of 4 charachters allowed in text widget. @ moment, when buttons pressed infinite amount of numbers shown in text widget. example: 123456 want 1234 case shown.

also if possible how change size of window contains widgets @ moment, window larger widgets whereas want same length. images sizing shown below:

original

what want window size be

based on "how have maximum of 4 charachters allowed": need have validation in program:
assuming want integer numbers in range of [1-4] (1, 2, 3, 4):

from tkinter import * root = tk()  def valfunc(txt):     if len(txt) <= 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() 

and window size need use geometry method window.


Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

sql - MySQL - Finding Empty relations -

linux - gzip: stdin: not in gzip format tar: Child returned status 1 tar: Error is not recoverable: exiting now -