2017-10-08 72 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。