August 5th, 2013, 08:10 AM
-
Help needed in Tkinter python
Hi Friends,
I am using Tkinter for gui. Actuallly I want to open a file and extract it in same folder where my file is present.
The python script is kept at some other location. Whenever I run the script and browse to my required file it extract it in folder where my script is present. Please find the attached my code.
Code:
#!/usr/bin/python
import subprocess
import os
from xml.etree import ElementTree as ET
from Tkinter import *
from tkFileDialog import askopenfilename
def main():
root=Tk()
global fname
fname = askopenfilename(filetypes[("allfiles","*"),"pythonfiles","*.py")])
print fname main()
### unzip .fzz file
subprocess.call(["unzip" ,fname])
August 5th, 2013, 10:15 AM
-
When a python script runs, it has a "current working directory", which is where any file-level operations are going to default to; by default it's going to be the directory where the script is.
If you want to unzip these files to a specific location, you have two options:
- use os.chdir to change the current working directory to where you want these files to go.
- tack on some argument to the unzip command to specify the output location
You can determine the directory of the selected file using os.path.dirname().