Python:尝试使用文本小部件(使用网格布局)扩展滚动条小部件时出错

Python:尝试使用文本小部件(使用网格布局)扩展滚动条小部件时出错,python,tkinter,Python,Tkinter,我正在尝试制作一个文本框,它的侧面有h滚动条 如何将其从上到下展开 (其他小部件使用sticky=N+S+E+W展开,但出现错误: TypeError:必须是str,而不是滚动条 以下是示例代码: from tkinter import * root = Tk() text = Text(root) text.grid(row=0, column=0) S = Scrollbar(root) S.grid(row=0, column=1) S.config(command=text.yvie

我正在尝试制作一个文本框,它的侧面有h滚动条

如何将其从上到下展开

(其他小部件使用
sticky=N+S+E+W展开,但出现错误:

TypeError:必须是str,而不是滚动条

以下是示例代码:

from tkinter import *

root = Tk()
text = Text(root)
text.grid(row=0, column=0)

S = Scrollbar(root)
S.grid(row=0, column=1)
S.config(command=text.yview)
text.config(yscrollcommand=S.set)

root.mainloop()

您的错误是由于命名冲突造成的:您已将滚动条命名为与
S
tkinter常量相同的方式

我建议您将tkinter作为tk进行
导入,而不是从tkinter import*
导入
,这样tkinter常量
S
将是
tk.S
,因此不会与您定义的变量混淆