python Tkinter:滚动条未添加到文本区域

python Tkinter:滚动条未添加到文本区域,python,tkinter,Python,Tkinter,serparate文件中的以下代码工作正常。它正在创建一个文本区域并向其中添加一个滚动条 root = Tkinter.Tk() text=Text(root,height=10,width=50,background='pink') scroll=Scrollbar(root) text.configure(yscrollcommand=scroll.set) scroll.config(command=text.yview) text.pack(side=LEFT) scroll.pack(

serparate文件中的以下代码工作正常。它正在创建一个文本区域并向其中添加一个滚动条

root = Tkinter.Tk()
text=Text(root,height=10,width=50,background='pink')
scroll=Scrollbar(root)
text.configure(yscrollcommand=scroll.set)
scroll.config(command=text.yview)
text.pack(side=LEFT)
scroll.pack(side=RIGHT,fill=Y)
但完全相同的代码在与其他代码合并时没有工作(main.py


当我从cmd提示符运行main.py文件时,它只是挂起。这里出了什么问题?

您试图对同一包含小部件同时使用
grid
pack
。你不能那样做。您需要对文本和滚动条使用
grid
,或者对按钮使用
pack

//================ other code
root = Tkinter.Tk()
root.geometry("800x600+100+0") # width, height, x ,y
button_1 =  Button(root,text="iphone file")
button_1.pack()
button_1.grid(row=0, column=0)
button_1.configure(command=openFile)

//------------------ following is the same code
text=Text(root,height=10,width=50,background='pink')
scroll=Scrollbar(root)
text.configure(yscrollcommand=scroll.set)
scroll.config(command=text.yview)
text.pack(side=LEFT)
scroll.pack(side=RIGHT,fill=Y)