hello seniors,

i am in need of getting some good tutorial or any helping example by which i can get an idea about how to serialize the objects in wxpython.
your help will be highly appreciated.

Regards
Punter

Dani AI

Generated

A short practical guide building on 's question and 's pointer to Python serialization: do not try to serialize live wx objects (Frames, Controls, Menus). wx widgets wrap C++ resources and internal handles that are not reliably picklable and will not survive a simple load/recreate cycle. Instead, persist the application state or model (the data the GUI shows) and recreate GUI controls from that state on startup.

A simple workflow:

  1. Identify the state to save (values, file lists, window geometry, user prefs).
  2. Convert any non-primitive types to plain Python types (dicts, lists, tuples, strings, numbers).
  3. Choose a format: JSON for portable, human-readable settings; pickle for richer Python objects (note: in modern Python there is no separate cPickle module — use pickle); shelve if you want a simple on-disk dict. Save on clean shutdown and restore at startup by applying values back to controls (e.g., set value, selection, size, position).

Practical tips and cautions:

  • Add a version field to saved files so you can migrate formats when your model changes.
  • For complex classes implement custom serialization (for example a to_dict/from_dict pair or __getstate__/__setstate__) so only safe, simple data is written.
  • Never unpickle untrusted data — see the official pickle security warnings.
  • For small configuration items, consider wx.FileConfig so settings go to the platform-appropriate location.
  • Do file IO off the GUI thread and marshal results back to the main thread to avoid freezes.

Relevant documentation: pickle — Python object serialization, json — JSON encoder and decoder, shelve — Python object persistence, wx.FileConfig.

Recommended Answers

All 4 Replies

Just serialize them with Python's pickle or cpickle module

thank you for replying.

is it any way so i can get an example or some helping tutorial that can show me how the serialization will be done with pickle or cpickle??

ok,let me check that link.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.