【发布时间】:2014-07-05 11:35:27
【问题描述】:
首先,我想解决这个问题:Python - tkinter 'AttributeError: 'NoneType' object has no attribute 'xview''
但是,在阅读完这篇文章后,我仍然对问题所在感到困惑。我有一个使用 Tkinter 的程序。其中有两个文本框,用户可以在其中输入文本。我希望这些框是可滚动的。但是,我这样做有一个问题。这是我的代码:
from Tkinter import *
def main():
window = Tk()
window.title("TexComp")
window.geometry("500x500")
window.resizable(height=FALSE,width=FALSE)
windowBackground = '#E3DCA8'
window.configure(bg=windowBackground)
instruction = Label(text="Type or paste your text into one box,\nthen paste the text you want to compare it too\ninto the other one.", bg=windowBackground).place(x=115, y=10)
text1 = Text(width=25).pack(side=LEFT)
text2 = Text(width=25).pack(side=RIGHT)
scroll1y=Scrollbar(window, command=text1.yview).pack(side=LEFT, fill=Y, pady=65)
scroll2y=Scrollbar(window, command=text2.yview).pack(side=RIGHT, fill=Y, pady=65)
mainloop()
if __name__ == '__main__':
main()
当我尝试运行此程序时,我在 scroll1y 和 scroll2y 滚动条上收到错误消息“'NoneType' 对象没有属性 'yview'”。我不确定为什么会这样并且一直无法找到明确的答案。感谢您的宝贵时间。
【问题讨论】:
-
这是一个非常相似的问题:stackoverflow.com/questions/23625407/…
标签: python python-2.7 tkinter