user729854
user729854

Reputation: 21

Creating a GUI for Python scripts

I use a python script record.py to record certain events.

The command work in this way:

python record.py <scriptname>

It stores the the script in local disk. Later you can replay the recorded script by simply saying:

python scriptname.py

All these actions (described above work correctly) but are done through command line (linux Terminal).

I want to make a GUI with two tabs (Record, Play):

  1. Record Tab: Has a textbox (for <scriptname>) and a button named record (which is linked with record.py script)

  2. Play Tab: Has a feature to include all the scripts that were recorded and button called play to run either a single script or entire bunch of scripts.

Upvotes: 2

Views: 13347

Answers (2)

Mark Nenadov
Mark Nenadov

Reputation: 6967

Daniel,

I suggest wxPython as well.

If you decide to go with wxPython, here is a broad outline of how you would make the tabs work. It requires you to fill in some blanks, but once you grasp the basics of wxPython, this will show you how to build a "Notebook" with tabs.

What you would basically do would be to have a main script (an outline of which is represented in the code sample as follows) and then have each panel represented as a separate file (in this example there is: panel1.py, panel2.py, panel3.py etc.). And the main script would run the individual panels through wxPython.

Your main script that handles the entire window would look something like this:

from wxPython.wx import *

class MainFrame(wxFrame):
        .
        .
        .

        def __init__(self, parent, id, title):
                .
                .
                .

                # Create the Notebook
                self.nb = wxNotebook(self, -1, wxPoint(0,0), wxSize(0,0), wxNB_FIXEDWIDTH)

                # Make PANEL_1 (filename: panel1.py)

                self.module = __import__("panel1", globals())
                self.window = self.module.runPanel(self, self.nb)

                if self.window:
                        self.nb.AddPage(self.window, "PANEL_1")


                # Make PANEL_2 (filename: panel2.py)

                self.module = __import__("panel2", globals())
                self.window = self.module.runPanel(self, self.nb)

                if self.window:
                        self.nb.AddPage(self.window, "PANEL_2")


                # Make PANEL_3 (filename: panel3.py)

                self.module = __import__("panel3", globals())
                self.window = self.module.runPanel(self, self.nb)

                if self.window:
                        self.nb.AddPage(self.window, "PANEL_3")

                .
                .
                .

But I must emphasize.... don't try the tabs right away, grasp the principles of how wxPython works first.

Upvotes: 4

Achim
Achim

Reputation: 15722

http://www.wxpython.org/ might help.

Upvotes: 3

Related Questions