python Tkinter:滚动条没有添加到textarea

时间:2013-03-29 14:40:23

标签: 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(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 :(得分:0)

您正尝试将gridpack同时用于相同的包含小部件。你不能这样做。您需要使用grid作为文本和滚动条,或使用pack作为按钮。