每当我在框中填充文本时,水平滚动条工作正常,直到文本显示在屏幕上。在
但是,如果行数大于屏幕上显示的行数,而我向下滚动文本,则水平滚动条将变为非活动状态,直到文本太长而无法再容纳一行时为止
以下是我的基本代码:
from Tkinter import *
import Tkinter,tkFileDialog, tkFont
w = Label(root, text="Hello, world!")
w.pack()
textfr=Frame(root)
t=Text(textfr, width=100, height=10,font=("Arial",12),wrap=NONE)
t.insert('1.0', 'here is my text to insert')
Yscroll=Scrollbar(textfr, orient=VERTICAL)
Xscroll=Scrollbar(textfr, orient=HORIZONTAL)
t.configure(yscrollcommand=Yscroll.set)
t.configure(xscrollcommand=Xscroll.set)
Yscroll.config(command=t.yview)
Xscroll.config(command=t.xview)
#pack everything
Yscroll.pack(side=RIGHT,fill=Y)
Xscroll.pack(side=BOTTOM,fill=X)
t.pack(side=LEFT, fill=BOTH, expand=TRUE)
textfr.pack(side=TOP, fill=BOTH, expand=TRUE)
root.mainloop()
唉,我找不到/google合适的解决方案,尽管这个问题很简单
有什么想法吗?在
这只是一个使用按钮的简单示例。更改for循环的range()语句中的数字以了解它的含义,您应该能够根据自己的需要调整此代码,希望这有帮助。在
相关问题 更多 >
编程相关推荐