Specify the dimensions of a Tkinter text box in pixels

You can do it by putting it inside a frame, forcing the frame to a fixed size by deactivating size propagation and configuring the entry to stick to the frame borders. Should work in a similar way with pack, too.

import Tkinter  # tkinter with small t for python 3
#import ttk  # nicer widgets

root = Tkinter.Tk()

mainFrame = Tkinter.Frame(root)
mainFrame.grid()
button = Tkinter.Button(mainFrame, text="dummy")
button.grid()


entryFrame = Tkinter.Frame(mainFrame, width=454, height=20)
entryFrame.grid(row=0, column=1)

# allow the column inside the entryFrame to grow    
entryFrame.columnconfigure(0, weight=10)  

# By default the frame will shrink to whatever is inside of it and 
# ignore width & height. We change that:
entryFrame.grid_propagate(False)
# as far as I know you can not set this for x / y separately so you
# have to choose a proper height for the frame or do something more sophisticated

# input entry
inValue = Tkinter.StringVar()
inValueEntry = Tkinter.Entry(entryFrame, textvariable=inValue)
inValueEntry.grid(sticky="we")


root.mainloop()

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)