Hi,

I am creating a GUI using wxPython. The first window involves making a box with attributes such as title (Big Font Text, results from a file that i will be reading in, want an arrow that changes position depending on results. So think of it like a progress bar.

Then i repeat this 8 times just with different attributes. However, i am unable to create the first base class with the methods and parameters to do this. Example

Class Zone(title,text_1,text_2,value_1,value_2)

when i create my front i want to then create a "zone" object with the parameters being fed in from a list.
This is what i have so far:

import wx

class mainFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title,style=wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.CAPTION)

        mainBox = wx.BoxSizer(wx.VERTICAL)
        tiles = wx.GridSizer(3, 3, 60, 60)

        for i in range(0,9):
            panel = wx.Panel(self, -1, style=wx.DOUBLE_BORDER)
            tiles.Add(panel, flag=wx.EXPAND)
        mainBox.Add(tiles, 1, wx.EXPAND | wx.TOP| wx.ALL, 30)
        self.SetSizer(mainBox)

        self.SetBackgroundColour(wx.Colour(120,200,200,10))
        self.Maximize()
        self.Show()


app = wx.App(0)
frame = mainFrame(None, -1, 'System Overview.py')
app.MainLoop()

It got messy real quick on my first attempt as i had to manually place buttons, text, bitmaps, listbox etc. Trying to put them in functions and minimise code.

Recommended Answers

All 4 Replies

To set the background from a list for example would be like the following, and you would use other input parameters in a similar manner, although I don't think I understood your question correctly.

import wx

class mainFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title,style=wx.MINIMIZE_BOX|wx.SYSTEM_MENU|wx.CAPTION)

        mainBox = wx.BoxSizer(wx.VERTICAL)
        tiles = wx.GridSizer(3, 3, 60, 60)

        colors = ("red", "blue", "green", "yellow", "white",
                  "lightgreen", "lightblue", "purple", "brown")
        for ctr in range(0,9):
            panel = wx.Panel(self, -1, style=wx.DOUBLE_BORDER)
            txt=wx.StaticText(panel, label="title "+ str(ctr+1))
            panel.SetBackgroundColour(colors[ctr])
            tiles.Add(panel, flag=wx.EXPAND)
        mainBox.Add(tiles, 1, wx.EXPAND | wx.TOP| wx.ALL, 30)
        self.SetSizer(mainBox)

        self.SetBackgroundColour(wx.Colour(120,200,200,10))
        self.Maximize()
        self.Show()


app = wx.App(0)
frame = mainFrame(None, -1, 'System Overview.py')
app.MainLoop()

Hi,

So imagine a box (panel) now i want that to be like a class that i can replicate 8 times so i want it to be like those tiles in windows 8.

However, each box has the attributes/properties that i mentioned (title, text, a chart)
then i just want to say run it through a loop and fetch the various parameters from a dictionary or list.
wx.Frame wouldn't let me create new classes in within the class itself.

Thanks for the panel colour code though, that will definitely come in handy

One single class and a for loop will work fine for that. Just open the file under the for loop and use those parameters. If you want to save something, say references to the specific panels, use a dictionary: key=panel number, pointing to a list of whatever you want.

so is it possible to do this?

class xx(wx.Frame)
   WHILE LOOP HERE

   class Zone

   def 1
   def 2

on a side note, how can i add an expandable box to display the results? so just want a box of x size that grows as i add stuff to it. I looked into flexigridsizer but i have panels already and it seems to be causing errors.

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.