2017-10-08 71 views
0

我在执行带有侧面滚动的文本框时出现问题(下图)。 以下代码:Python滚动文本框

from tkinter import * 
from tkinter import ttk 

root = Tk() 
[enter image description here][1] 
text1 = Text(root, wrap=WORD, height=10, width=50) 
y_scrollbar = ttk.Scrollbar(orient=VERTICAL, command=text1.yview) 
text1['yscrollcommand'] = y_scrollbar.set 

y_scrollbar.grid(root, row=0, column=1) 
text1.grid(row=0, column=0) 

root.mainloop() 

我一直在y_scrollbar.grid收到错误(根,行= 0,列= 1)。

回答

1

您错误地使用了.grid()。您应该将此y_scrollbar.grid(root, row=0, column=1)更改为y_scrollbar.grid(row=0, column=1)。无需包含root。