hystrix
Posts: 56
Joined: Mon Jan 07, 2013 12:44 pm

Help with tkinter subprocess

Mon Aug 31, 2015 2:10 pm

I am trying to convert a Python script (that I have been using from the command line) into a GUI project. I want to start a recording from my sound card when I press a button. I have been using the following subprocess in my Python script without problems, but when use tkinter to create a GUI, the subprocess is called, but I end up with a 44byte wave file i.e. the subprocess ends almost as quickly as it starts. What should happen is it starts recording when I press a button (with duration = infinity) until I kill the process later.

Here's the simplified code:

Code: Select all

#!/usr/bin/python
from Tkinter import *
import subprocess

root = Tk() #Makes the window
root.wm_title("Recorder") #Makes the title that will appear in the top left
root.config(background = "#828481") #sets background color to white

def btnStartClicked():  
    process = subprocess.Popen ("arecord -Dhw:sndrpiwsp -r 192000 -c 2 -f S32_LE -d0 /media/USBSTICK/recording.wav", shell = True) #channels = 2 for stereo
    Log.insert(0.0, "Recording started")
    
#Frame and its contents
myFrame = Frame(root, width=200, height = 600, bg="#C8F9C4", highlightthickness=2, highlightbackground="#111")
myFrame.grid(row=0, column=1, padx=10, pady=2, sticky=N+S)

btnFrame = Frame(myFrame, width=200, height = 200, bg="#C8F9C4")
btnFrame.grid(row=1, column=0, padx=10, pady=2)

Log = Text(myFrame, width = 30, height = 3, takefocus=0, highlightthickness=1, highlightbackground="#333")
Log.grid(row=2, column=0, padx=10, pady=2)

redBtn = Button(btnFrame, text="Start", command=btnStartClicked, bg="#6EEC77")
redBtn.grid(row=0, column=0, padx=10, pady=2)

root.mainloop() #start monitoring and updating the GUI. Nothing below here runs.
I know I'm doing something wrong somewhere, so I would appreciate some help.

Many thanks.

Return to “Python”