Reputation: 53031
I noticed that the width argument for the Tkinter entry widget is in characters, not pixels.
Is it possible to adjust the width in pixels?
Upvotes: 13
Views: 32752
Reputation: 11
It is still possible to set the width of an entry widget with math, see if you set the width of an entry widget to 1, that means that the entry widget can fit one character only, and in most platforms the default points in a font (without the --font entry) is 1.33px in 90 DPI, so, with these information, you can try this code``
import tkinter as tk
root = tk.Tk()
fontpoints = 1 # font size is 1 (change this if needed)
width = round(1.33 * fontpoints)
entry = tk.Entry(root, width=width, font=fontpoints)
entry.pack()
hopefully this helps
Upvotes: 1
Reputation: 386332
You cannot specify the width in pixels using the '-width' option, but there are ways to accomplish the same thing. For example, you could pack an entry in a frame that has no border, turn off geometry propagation on the frame, then set the width of the frame in pixels.
Upvotes: 6
Reputation: 880
You can use "ipadx" and "ipady" while packing the "Entry" widget.
You can also use it with "grid".
import tkinter as tk
root = tk.Tk
e = tk.Entry()
e.pack(ipadx=100, ipady=15)
tk.mainloop()
Upvotes: 3
Reputation: 1349
You can also use the Place geometry manager:
entry.place(x=10, y=10, width=100) #width in pixels
Upvotes: 22