无法在 Tkinter 中禁用自动换行 [英] unable to disable word wrap in Tkinter

查看:49
本文介绍了无法在 Tkinter 中禁用自动换行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在禁用自动换行的文本窗口中书写 &水平滚动条,像这样:

I'm trying to write in a text window with word wrapping disabled & horizontal scrollbar, like this:

root = Toplevel()
root.geometry("%dx%d+0+0" % (350,400))
af=Frame(root)
chtext = Text(af, width=45, wrap=None,font=("Arial",12)) 
chxscrollbar=Scrollbar(chtext, orient=HORIZONTAL, command=chtext.xview)
chtext["xscrollcommand"]=chxscrollbar.set
af.pack(fill="both", expand=True)
chtext.pack(side="left", expand=1, fill="both")
chxscrollbar.pack(side="bottom", fill="x", expand=False)

我的问题是它仍然对我写的内容进行自动换行...我是否遗漏了一些明显的东西???

my problem is that it still wordwraps what I write into it... am I missing something obvious???

谢谢!

推荐答案

None 不是 wrap 选项的有效值.您需要使用字符串 "none" 或 tkinter 变量 NONE.通过指定 python 值 None,您实际上是在请求默认值,即 "char"

None is not a valid value for the wrap option. You need to use the string "none" or the tkinter variable NONE. By specifying the python value None you are actually requesting the default value, which is "char"

chtext = Text(af, width=45, wrap="none", font=("Arial",12)) 

这篇关于无法在 Tkinter 中禁用自动换行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆