And now for a pair of questions that are completely different:
1) I'd like to be able to bind callbacks to presses of the arrow
buttons on the keyboard. How do you say that in Tkinter?
2) The function 'listdir' in os.path returns a list of all the files
in the given directory - how do I get hold of a list of its
subdirectories?
Any help will be greatly appreciated.
Peace,
STM 4 1068
os.walk gives an object with all files in a tree, e.g.
f = os.walk('c:\\temp')
for i in f:
print i
def walktree(self,top=".", depthfirst=False):
"""
Walk a directory tree, starting from 'top'
This code is based on os.path.walk, with the callback function
replaced by a yield and recursion replaced by iteration
"""
if type(top) != types.StringType:
raise TypeError("top must be a string")
# decide which end of the stack to pop
if depthfirst:
index = -1
else:
index = 0
dirstack = [top]
while dirstack:
top = dirstack.pop(index)
try:
names = os.listdir(top)
except os.error:
return
yield top, names
dirs = []
for name in names:
name = os.path.join(top, name)
try:
st = os.lstat(name)
except os.error:
continue
if stat.S_ISDIR(st.st_mode):
dirs.append(name)
# the depth-first results look 'backwards' to me
# so I'm changing them to fit my expectations
if depthfirst:
dirs.reverse()
dirstack.extend(dirs)
this function might be useful
Sean McIlroy wrote: And now for a pair of questions that are completely different:
1) I'd like to be able to bind callbacks to presses of the arrow buttons on the keyboard. How do you say that in Tkinter?
2) The function 'listdir' in os.path returns a list of all the files in the given directory - how do I get hold of a list of its subdirectories?
Any help will be greatly appreciated.
Peace, STM
Sean McIlroy wrote: 1) I'd like to be able to bind callbacks to presses of the arrow buttons on the keyboard. How do you say that in Tkinter?
<Up>, <Down>, <Left>, <Right> http://effbot.org/books/tkinterbook/...d-bindings.htm
For an ordinary 102-key PC-style keyboard, the special keys are Cancel
(the Break key), BackSpace, Tab, Return(the Enter key), Shift_L (any
Shift key), Control_L (any Control key), Alt_L (any Alt key), Pause,
Caps_Lock, Escape, Prior (Page Up), Next (Page Down), End, Home,
Left, Up, Right, Down, Print, Insert, Delete, F1, F2, F3, F4, F5, F6,
F7, F8, F9, F10, F11, F12, Num_Lock, and Scroll_Lock.
2) The function 'listdir' in os.path returns a list of all the files in the given directory - how do I get hold of a list of its subdirectories?
listdir returns files and directories; use os.path.isdir(path) to check if path is
a directory:
for name in os.listdir(path):
p = os.path.join(path, name)
if os.path.isdir(p):
...
</F>
....how do I get hold of a list of its subdirectories?
This does what you asked for:
import os
targetpath='c:\\'
all=os.listdir(targetpath)
subdirs=[x for x in all
if os.path.isdir(os.path.join(targetpath, x))]
But you may need to take a look at os.walk (as others
have suggested) also.
Larry Bates
Sean McIlroy wrote: And now for a pair of questions that are completely different:
1) I'd like to be able to bind callbacks to presses of the arrow buttons on the keyboard. How do you say that in Tkinter?
2) The function 'listdir' in os.path returns a list of all the files in the given directory - how do I get hold of a list of its subdirectories?
Any help will be greatly appreciated.
Peace, STM This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Miguel Dias Moura |
last post by:
Hello,
I am creating a master page for a web site.
All pages created from this master page will use the same theme.
However I am not able to add the theme in my master page.
Why is that?
...
|
by: Ben |
last post by:
Hi, I'm using images in my menu control. I have my menu setup based on this
example:
http://msdn2.microsoft.com/en-US/library/system.web.ui.webcontrols.menuitembinding.imageurlfield(VS.80).aspx
...
|
by: Joey |
last post by:
Hello,
I have tried to programmatically set the theme for my master page by
putting code in a "Page_PreInit" fuction in the master page's code
behind. However, when I set a breakpoint there and...
|
by: Ron |
last post by:
I have an application that requires a login at each visit to the site and can
only be accessed by a login.
A user can have different themes depending if it was assigned in there
profile.
Theme...
|
by: greg |
last post by:
Hi all,
Is there a way to get the current theme name at design time?
I'm trying to write a custom control for which I need to use images from the
current theme. I have asigned a theme to the...
|
by: Neil Jones |
last post by:
Hello,
I would like to create my own theme(s) for a couple of my own blog
sites. I am hoping a few better themes could bring lot more readers.
So far, I have stayed with the default wordpress...
|
by: Jonathan Wood |
last post by:
Greetings,
So, I now have a custom IHttpModule class that I use to establish the Theme
for each page, based on the user's settings. Seems to work just fine. Thanks
to everyone who made helpful...
|
by: Henry Stock |
last post by:
I am having trouble referencing a theme in my ASP.NET project.
I was following a model that allowed for multiple themes. So The theme that
I have is stored in named "Base" under the App_Theme...
|
by: econVictim |
last post by:
i have a user profile oriented website where every page has a form in it. I want people to submit the form and cause a refresh...
I also want the page to refresh if they hit the back button so...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: jfyes |
last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
by: Shællîpôpï 09 |
last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
|
by: af34tf |
last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
| |