Python 3.x 如何将滚动条移动到文本小部件内部
我有这个密码Python 3.x 如何将滚动条移动到文本小部件内部,python-3.x,tkinter,Python 3.x,Tkinter,我有这个密码 from tkinter import * root = Tk() root.geometry("1200x1000+30+30") # width x height + x_offset + y_offset: T = Text(root, height=10, width=100) T.place(x=20, y=30) for i in range(40): T.insert(END, "This is line %d\n"
from tkinter import *
root = Tk()
root.geometry("1200x1000+30+30")
# width x height + x_offset + y_offset:
T = Text(root, height=10, width=100)
T.place(x=20, y=30)
for i in range(40):
T.insert(END, "This is line %d\n" % i)
yscroll = Scrollbar(command=T.yview, orient=VERTICAL)
T.configure(yscrollcommand=yscroll.set)
yscroll.pack(side="right", fill="y", expand=False)
root.mainloop()
srollbar位于窗口框架上,是否有办法将其移动到文本区域的内部和右侧边缘 可能还有另一种方法,但我会使用
tkinter.ScrolledText
中包含的ScrolledText
小部件
from tkinter import *
import tkinter.scrolledText
root = Tk()
root.geometry("1200x1000+30+30")
# width x height + x_offset + y_offset:
T = ScrolledText(root, height=10, width=100)
T.place(x=20, y=30)
for i in range(40):
T.insert(END, "This is line %d\n" % i)
root.mainloop()
这会自动将滚动条放在文本框内
从中,我还了解到,您可以使用place
而不是pack
来定位滚动条,然后在
from tkinter import *
root = Tk()
root.geometry("1200x1000+30+30")
# width x height + x_offset + y_offset:
T = Text(root, height=10, width=100)
T.place(x=20, y=30)
for i in range(40):
T.insert(END, "This is line %d\n" % i)
yscroll = Scrollbar(command=T.yview, orient=VERTICAL)
yscroll.place(in_=T, relx=1.0, relheight=1.0, bordermode="outside")
T.configure(yscrollcommand=yscroll.set)
root.mainloop()
到目前为止,您做了什么添加标记、语法您可以使用place,但它很少是最好的解决方案。