How would I specify the dimensions of a Tkinter text box using pixels? I am not trying to change the font size, I am using this to help me scale it to the size of the window.
You can configure the size of an Entry widget such as its width using the width property. However, tkinter has no height property to set the height of an Entry widget. To set the height, you can use the font('font_name', font-size) property.
In this code, we have allowed users to expand the window size for only 50 pixels only. as you can see the geometry is 300×400 and maxsize is 350 for width & 450 for height.
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()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With