python - NameError: global name 'END' is not defined -


i have found code scrollbar working fine.

from tkinter import *  master = tk()  scrollbar = scrollbar(master) scrollbar.pack(side=right, fill=y)  listbox = listbox(master, yscrollcommand=scrollbar.set) in range(10000):     listbox.insert(end, str(i)) listbox.pack(side=left, fill=both)  scrollbar.config(command=listbox.yview)  mainloop() 

i try use in code this:

import tkinter tk  class interface(tk.frame):     def __init__(self,den):         self.tklist()          #in code, tklist not called here. called here minimize code         #there stuff in here      def tklist(self):         scrollbar = tk.scrollbar(den)         self.lst1 = tk.listbox(den, selectmode="single", width="100", yscrollcommand=scrollbar.set)         in range(1000):             self.lst1.insert(end, str(i))         self.lst1.pack(side=left, fill=both)         scrollbar.config(command=lst1.yview)  den = tk.tk() den.title("search")  inter = interface(den)  den.mainloop() 

but when ran above code, got error on insertion line.

nameerror: global name 'end' not defined 

by way, tried find documentation , a link effbot closest got still couldn't understand wrong.

end, left, , both reside in tkinter namespace. thus, need qualified placing tk. before them:

for 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, import them explicitly if want:

from tkinter import both, end, left 

Comments

Popular posts from this blog

c++ - How to add Crypto++ library to Qt project -

jQuery Mobile app not scrolling in Firefox -

How to use vim as editor in Matlab GUI -