Tkinter in PyRun_SimpleString(char* s)

Torsten Mohr tmohr at s.netic.de
Sun Sep 15 06:29:34 CEST 2002


Hi,

it doesn't seem to be as easy as i thought to load a script
from a C program and execute it, if i import Tkinter, it fails:


Traceback (most recent call last):
  File "<string>", line 31, in ?
  File "<string>", line 27, in __init__
  File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 2249, in __init__
    Widget.__init__(self, master, 'frame', cnf, {}, extra)
  File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 1750, in __init__
    BaseWidget._setup(self, master, cnf)
  File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 1725, in _setup
    _default_root = Tk()
  File "/usr/lib/python2.1/lib-tk/Tkinter.py", line 1476, in __init__
    baseName = os.path.basename(sys.argv[0])
AttributeError: 'sys' module has no attribute 'argv'


The script i try to run is the example from the latest library
documentation of Tkinter.

The C program looks like this, it is also a slightly changed
example.

It seems there are some initialisations missing, what do i need
to do to set it all up properly?


Best regards,
Torsten.


int main(int argc, char** argv) {
        // routine to load a file
        f = slFileLoad("script.py", 0);

        Py_SetProgramName(argv[0]);

        Py_Initialize();

        PyRun_SimpleString(f->address);

        Py_Finalize();

        return EXIT_SUCCESS;
}





More information about the Python-list mailing list