【发布时间】:2025-12-26 21:10:11
【问题描述】:
root = tk.Tk()
text = tk.Text(root, width = 40, height = 1, wrap = 'word')
text.pack(pady = 50)
after_id = None
# Now i want to increase the height after wraping
def update():
line_length = text.cget('width')
lines = int(len(text.get(1.0, 'end'))/line_length) + 1 # This is to get the current lines.
text.config(height = lines) # this will update the height of the text widget.
after_id = text.after(600, update)
update()
root.mainloop()
嗨,我正在制作一个文本小部件,我想在某些输入时更新它,否则让它保持空闲状态,现在我正在使用此代码。但是我不知道在没有输入或没有按下按钮时如何让它保持空闲状态。
我知道有更好的方法来执行此操作,但还没有找到。请帮忙!!!
【问题讨论】:
标签: python python-3.x tkinter tkinter-text