Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Specify the dimensions of a Tkinter text box in pixels

Tags:

python

tkinter

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.

like image 383
xxmbabanexx Avatar asked Feb 15 '13 02:02

xxmbabanexx


People also ask

How do you change the size of an entry in Tkinter?

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.

What is the maximum size of a window in Tkinter?

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.


1 Answers

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() 
like image 67
Gonzo Avatar answered Sep 19 '22 06:09

Gonzo