AttributeError: 'NoneType' object has no attribute 'delete'

前端 未结 3 820
旧巷少年郎
旧巷少年郎 2020-12-21 11:33

I have run into this issue and I can\'t understand why.

I took my code from my application and made this test code so you don\'t have to go through a bunch of junk t

3条回答
  •  伪装坚强ぢ
    2020-12-21 12:26

    The reason this is happening is because you are gridding it in the same variable. If you change your code to the following, it should work:

    import Tkinter as tk
    def main():
        mainWindow = tk.Tk()
        v = tk.StringVar()
        entryBox = tk.Entry(mainWindow, textvariable=v)
        def test():
            entryBox.delete(0,20)
        testButton = tk.Button(mainWindow, text='Go!', command=test, padx=10)
        testButton.grid(row=2, column=0) 
        entryBox.grid(column=0, row=1)
        tk.mainloop()
    main()
    

    The reason this works is because grid() does not return anything.

提交回复
热议问题