Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 3.x 如何将滚动条移动到文本小部件内部_Python 3.x_Tkinter - Fatal编程技术网

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,但它很少是最好的解决方案。