/ / python Tkinter:スクロールバーがテキストエリアに追加されない - python、tkinter

python Tkinter:スクロールバーがtextareaに追加されない - python、tkinter

別のファイル内の次のコードは問題なく動作しています。テキスト領域を作成し、それにスクロールバーを追加しています。

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

//================ 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)

そして、私はcmdプロンプトからmain.pyファイルを実行すると、それだけでハングアップします。ここで何がおかしいのですか?

回答:

回答№1は0

両方を使用しようとしています grid そして pack 同じ包含ウィジェット用。それをしてはいけない。どちらかを使う必要があります grid テキストとスクロールバーの場合は pack ボタン用です。