以最佳方式设置入口对象的宽度该字符串完全可见
我有以下代码:
from tkinter import *
from tkinter import simpledialog
def resize(lbl):
USER_INP = simpledialog.askstring(title="User input",
prompt="Please enter your message here:")
lbl['state'] = 'normal'
lbl.insert(0, f"Text was \'{USER_INP}\'.")
lbl['state'] = 'readonly'
lbl['width'] = 50
top = Tk()
lbl_entry = Entry(top, state="readonly", justify='center', width=10)
lbl_entry.grid(column=0, row=1)
bt_adjust = Button(top, text = "Resize Entry", command=lambda:resize(lbl_entry))
bt_adjust.grid(column=0, row=0)
top.mainloop()
按下按钮bt_adjust
条目>条目
对象的宽度自动调整。他们的一种方式是以这种方式动态设置宽度的方式,该文本已在entry
元素上完全显示,但是如果宽度较小一点,则文本将不再完全显示?
I have following code:
from tkinter import *
from tkinter import simpledialog
def resize(lbl):
USER_INP = simpledialog.askstring(title="User input",
prompt="Please enter your message here:")
lbl['state'] = 'normal'
lbl.insert(0, f"Text was \'{USER_INP}\'.")
lbl['state'] = 'readonly'
lbl['width'] = 50
top = Tk()
lbl_entry = Entry(top, state="readonly", justify='center', width=10)
lbl_entry.grid(column=0, row=1)
bt_adjust = Button(top, text = "Resize Entry", command=lambda:resize(lbl_entry))
bt_adjust.grid(column=0, row=0)
top.mainloop()
After pressing the button bt_adjust
the width of the Entry
object is adjusting automatically. Is their a way to set the width dynamically in that way the text is fully displayed on the Entry
element but if the width would be a little smaller the text wouldn't be fully displayed anymore?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这有帮助吗?通过使用
len()
来自动调整大小。第10行中的代码:
调整大小之前的屏幕截图:
调整大小之后:
Does this help? By using
len()
to adjusting automatically resizing.code in line 10:
Screenshot before resizing:
AScreenshot after resizing: