Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8777943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T19:24:09+00:00 2026-06-13T19:24:09+00:00

My friend has an application written in C that comes with a GUI made

  • 0

My friend has an application written in C that comes with a GUI made using GTK under Linux. Now we want to rewrite the GUI in python (wxpython or PyQT).

I don’t have experience with Python and don’t know how to make Python communicate with C. I’d like to know if this is possible and if yes, how should I go about implementing it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T19:24:11+00:00Added an answer on June 13, 2026 at 7:24 pm

    Yes its possible to call ‘C’ functions from Python.

    Please look into SWIG(deprecated) also Python provides its own Extensibility API. You might want to look into that.

    Also google CTypes.

    LINKS:

    Python Extension

    A simple example:
    I used Cygwin on Windows for this. My python version on this machine is 2.6.8 – tested it with test.py loading the module called “myext.dll” – it works fine. You might want to modify the Makefile to make it work on your machine.

    original.h

    #ifndef _ORIGINAL_H_
    #define _ORIGINAL_H_
    
    int _original_print(const char *data);
    
    #endif /*_ORIGINAL_H_*/
    

    original.c

    #include <stdio.h>
    #include "original.h"
    
    int _original_print(const char *data)
    {
      return printf("o: %s",data);
    }
    

    stub.c

    #include <Python.h>
    #include "original.h"
    
    static PyObject *myext_print(PyObject *, PyObject *);
    
    static PyMethodDef Methods[] = {
      {"printx", myext_print, METH_VARARGS,"Print"},
      {NULL, NULL, 0, NULL}
    };
    
    PyMODINIT_FUNC initmyext(void)
    {
      PyObject *m;
      m = Py_InitModule("myext",Methods);
    }
    
    static PyObject *myext_print(PyObject *self, PyObject *args)
    {
      const char *data;
      int no_chars_printed;
      if(!PyArg_ParseTuple(args, "s", &data)){
          return NULL;
      }
        no_chars_printed = _original_print(data);
        return Py_BuildValue("i",no_chars_printed);  
    }
    

    Makefile

    PYTHON_INCLUDE = -I/usr/include/python2.6
    PYTHON_LIB = -lpython2.6
    USER_LIBRARY = -L/usr/lib
    GCC = gcc -DNDEBUG -g -O3 -Wall -Wstrict-prototypes -fPIC -DMAJOR_VERSION=1 -DMINOR_VERSION=0 -I/usr/include -I/usr/include/python2.6 
    
    win32 : myext.o
        - gcc -shared myext.o $(USER_LIBRARY) $(PYTHON_LIB) -o myext.dll
    
    linux : myext.o
        - gcc -shared myext.o $(USER_LIBRARY) $(PYTHON_LIB) -o myext.so
    
    myext.o: stub.o original.o
        - ld -r stub.o original.o -o myext.o
    
    stub.o: stub.c
        - $(GCC) -c stub.c -o stub.o
    
    original.o: original.c
        - $(GCC) -c original.c -o original.o
    
    clean: myext.o
        - rm stub.o original.o stub.c~ original.c~ Makefile~
    

    test.py

    import myext
    myext.printx('hello world')
    

    OUTPUT

    o: hello world

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My friend has a Phonegap application (written in JavaScript) that starts off with something
Friend of mine has a problem :). There is an application written in Visual
A friend of mine has to use an internally-written Windows application to perform part
A friend of mine has inherited an old Joomla 1.0.x site, that amongst other
A friend of mine has to send a normal email using ONLY HTML/HTML5 (or
My friend says that Django only has 1 thread or something? And I have
My friend and I want to write a Facebook application. We've narrowed down the
I got a Windows Phone 7 application project from a friend. Now I downloaded
We are developing an application in that we are providing VOIP feature using pjsip.We
I created a little Swing Application. Now I gave it to a friend to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.