NameError: global name 'END' is not defined

前端 未结 2 904
攒了一身酷
攒了一身酷 2020-12-07 02:42

I have found this code about scrollbar is just working fine.

from tkinter import *

master = Tk()

scrollbar = Scrollbar(master)
scrollbar.pack(side=RIGHT,          


        
相关标签:
2条回答
  • 2020-12-07 03:32

    END, LEFT, and BOTH all reside in the tkinter namespace. Thus, they need to be qualified by placing tk. before them:

    for i in range(1000):
        self.lst1.insert(tk.END, str(i))
    self.lst1.pack(side=tk.LEFT, fill=tk.BOTH)
    scrollbar.config(command=lst1.yview)
    

    Or, you could import them explicitly if you want:

    from tkinter import BOTH, END, LEFT
    
    0 讨论(0)
  • 2020-12-07 03:32

    use "end" instead of END

    from tkinter import *
    self.lst1.insert("end", str(i))
    
    0 讨论(0)
提交回复
热议问题