Ttkinter Text控件开启滚动条
时间: 2023-07-20 14:23:35 浏览: 165
要在Ttkinter Text控件中开启滚动条,可以使用Scrollbar和ScrolledText模块。以下是一个示例代码:
```python
from tkinter import *
from tkinter import scrolledtext
root = Tk()
root.title("ScrolledText Example")
# 创建一个ScrolledText控件并设置大小
txt = scrolledtext.ScrolledText(root, width=40, height=10)
txt.grid(column=0, row=0)
# 创建一个Scrollbar控件并设置与ScrolledText控件绑定
scrollbar = Scrollbar(root, command=txt.yview)
scrollbar.grid(column=1, row=0, sticky='NS')
# 设置ScrolledText控件的y轴滚动条与Scrollbar控件绑定
txt.config(yscrollcommand=scrollbar.set)
root.mainloop()
```
这个示例代码中创建了一个ScrolledText控件,然后创建了一个Scrollbar控件,并且将Scrollbar控件与ScrolledText控件绑定。最后,设置ScrolledText控件的y轴滚动条与Scrollbar控件绑定,这样就可以在ScrolledText控件中开启滚动条了。
阅读全文
相关推荐


















