无法在 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))