1

I don't think this has been asked before, but I read similar questions and none of them could solve my problem. I am making a file management in Tkinter using sqlite3. It has a 'write' button that, when clicked, opens a new notepad file using os.system. However, the code gets stuck here and doesn't proceed to the next further lines.

def openfile(uid, filename):
if filename=='':
    mb.showerror('Missing Input', 'Please specify a file name.')
else:
    try:
        os.system("notepad " +filename+".txt") #FREEZES HERE
        now=datetime.now()
        today= str(now.day) + '/' + str(now.month) +'/' + str(now.year)
        filecur.execute("SELECT * FROM File_Data")
        f=filecur.fetchall()
        print(f)
        filecur.execute("insert into File_Data (UID, FileName, Date_) values (?, ?, ?)", ( uid, filename, today))
        fileconn.commit()
    except:
        raise
        mb.showerror('Error','Looks like something is wrong. Please try again.')
        sys.exit(0)

If someone could help, that'd be great. Thank you!

1 Answers1

2

That's because os.system() does wait for its process to complete before returning.

Problem can be solved either by using threading or sub-process module.

Read more here: http://docs.python.org/library/subprocess.html

Arbazz Hussain
  • 1,622
  • 2
  • 15
  • 41