python - Accessing Temp Directory On Tkinter -
im new in page , love answers nice job, of users, im new on python , wanna make print of dir in entry or label doesnt matter example:
def directory(): os.listdir('/') files=stringvar() files.set(directory) entry=entry(root, textvariable=files).grid()
obviously in tkinter, last code make "print" list of directories, make me list horizontal ',' each folder different, want vertical list on "entry" or "label", suppose later need scroll bar but, there no problem, , make same temporal folder on windows that...
def directory(): os.listdir('%temp%') files=stringvar() files.set(directory) entry=entry(root, textvariable=files).grid()
but %temp% doesnt works directly on python how can make listdir of folder?
since displaying contents of directory going require multiple lines of text, 1 each item in it, have use atk.label
ortk.text
widget since tk.entry
can handle single line of text.
in addition you'll need convert thelist
that os.listdir()
returns multi-line string before setting itstext
option. regardless, in order use yourdirectory()
function needs return value useful.
the following code these basic things , shows how expand value of the%temp%
environment variable usingos.path.expandvars()
. alternatively, can same value using thetempfile.gettempdir()
function sukrit recommended.
import os tkinter import * def directory(folder): return '\n'.join(os.listdir(folder)) # turn list multiline string class app: def __init__(self, master): frame = frame(master) frame.pack() files = directory(os.path.expandvars('%temp%')) self.label = label(root, text=files) self.label.pack(side=left) root = tk() app = app(root) root.mainloop()
Comments
Post a Comment