Help me figure this out please ?

Post here if you need help with creating a Graphical User Interface in Python.

Help me figure this out please ?

Postby Joseaguirre » Tue Aug 06, 2013 1:40 pm

What i want this script to do is to look for a file, whatever you put in so lets say inside of my program files i want python to open skype so i type its name and press enter and nothing happens, i checked the key.event and i think it is set correctly ?
Can anyone tell me whats going on please?

Code: Select all
import sys
from Tkinter import *
import os
from subprocess import Popen

root = Tk()
directory = 'C:\program files'
filenames = list(os.walk(directory))[0][2]
print list(os.walk(directory))[0]
print list(os.walk(directory))[0][2]

string = ''
def main(event):
    global string
    global directory
    if event.keycode == 36 :
        for filename in filenames:
            if string in filename:
                Popen(filename, shell=True)
    if event.keycode == 46 or event.keycode == 8:
        string = string[:-1]
        string += event.char.strip()
    print 'string:', string
    print 'matches:', [i for i in filenames if string in i]

frame = Frame(root, width=400, height=400)
frame.bind("<Key>", main)

Posts: 1
Joined: Tue Aug 06, 2013 1:37 pm

Re: Help me figure this out please ?

Postby stranac » Tue Aug 06, 2013 5:32 pm

That is not the correct way to use os.walk().

What do you get when you print filenames?
Is it what you expected?
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
Posts: 1111
Joined: Thu Feb 07, 2013 3:42 pm

Return to GUI

Who is online

Users browsing this forum: No registered users and 3 guests