How do I set the width of an Tkinter Entry widget in pixels?

徘徊边缘 提交于 2019-12-30 08:50:08

问题


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?


回答1:


You cannot specify the worth 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, then set the width of the frame in pixels.




回答2:


You can also use the Place geometry manager:

entry.place(x=10, y=10, width=100) #width in pixels



回答3:


You can use "ipadx" and "ipady" while packing the "Entry" widget.

You can also use it with "grid".

This will work in all versions of Python 3:

import tkinter as tk

root = tk.Tk

e = tk.Entry()
e.pack(ipadx=100, ipady=15)

tk.mainloop()



来源:https://stackoverflow.com/questions/6881010/how-do-i-set-the-width-of-an-tkinter-entry-widget-in-pixels

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!