Hello, everyone, I'm new to wxPython
I want to write a small program that link the menu in one frame with another frame that I created after. I've tried to use like EVT_BUTTON, but it won't work. How am I supposed to do this?
Thx for any help

Here is an example how to access one frame from the other via the instance ...

# create two frames with wxFrame
# access one frame from the other

import wx
import random

class Frame1(wx.Frame):
    def __init__(self, parent):
        # self will be the Frame1 instance
        wx.Frame.__init__(self, parent, wx.ID_ANY, title='Frame1', pos=(50, 50))
        self.SetBackgroundColour("green")
        # create a Frame2 instance, pass Frame1 instance self to Frame2
        self.frame2 = Frame2(None, self)
        # show Frame2
        self.frame2.Show()

        # create a button
        self.button1 = wx.Button(self, wx.ID_ANY, label='change Frame2 color')
        # bind mouse event to an action
        self.button1.Bind(wx.EVT_BUTTON, self.button1Click)

        # use a box sizer to lay out widgets
        sizer_v = wx.BoxSizer(wx.VERTICAL)
        # Add(widget, proportion, flag, border)
        sizer_v.Add(self.button1, 0, flag=wx.ALL, border=10)
        self.SetSizer(sizer_v)

    def button1Click(self, event):
        """
        button1 has been left clicked, do something
        """
        color_list = ['red', 'blue', 'white', 'yellow', 'magenta', 'black']
        # pick a color from the color_list at random
        color = random.choice(color_list)
        print(color)  # test
        # change color of Frame2 via instance self.frame2
        self.frame2.SetBackgroundColour(color)
        # now clear old colour, set to new colour
        self.frame2.ClearBackground()        


class Frame2(wx.Frame):
    # notice how the Frame1 instance is passed
    def __init__(self, parent, frame1):
        wx.Frame.__init__(self, parent, wx.ID_ANY, title='Frame2', pos=(450, 150))
        self.SetBackgroundColour("brown")
        # in case you have to use the Frame1 instance within Frame2 methods
        self.frame1 = frame1


app = wx.App(0)
# create a Frame1 instance and show the frame
frame1 = Frame1(None)
frame1.Show()
app.MainLoop()
commented: this may be what I need to my problem +0
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.