python - Show files in tkinter Scrollbar -
i tried modify scrollbar tkdoc (http://www.tkdocs.com/tutorial/morewidgets.html#scrollbar) in order show filelist of folder not work. can explain me why? , how fix it.
thanks lot.
from tkinter import * tkinter import ttk import os def filename(): path="c:\\temp" dir=os.listdir(path) fn in dir: print(fn) root = tk() l = listbox(root, height=5) l.grid(column=0, row=0, sticky=(n,w,e,s)) s = ttk.scrollbar(root, orient=vertical, command=l.yview) s.grid(column=1, row=0, sticky=(n,s)) l['yscrollcommand'] = s.set ttk.sizegrip().grid(column=1, row=1, sticky=(s,e)) root.grid_columnconfigure(0, weight=1) root.grid_rowconfigure(0, weight=1) l.insert(filename) root.mainloop()
you should specify insert
l.insert(end, filename)
in code, insert function filename. insert return value of filename function.
i renamed filename
get_filename
, , modified return filename list.
from tkinter import * tkinter import ttk import os def get_filenames(): path = r"c:\temp" return os.listdir(path) root = tk() l = listbox(root, height=5) l.grid(column=0, row=0, sticky=(n,w,e,s)) s = ttk.scrollbar(root, orient=vertical, command=l.yview) s.grid(column=1, row=0, sticky=(n,s)) l['yscrollcommand'] = s.set ttk.sizegrip().grid(column=1, row=1, sticky=(s,e)) root.grid_columnconfigure(0, weight=1) root.grid_rowconfigure(0, weight=1) filename in get_filenames(): l.insert(end, filename) root.mainloop()
Comments
Post a Comment