| | |
(HELP) wxPython: Update other panels from event triggered in another panel
![]() |
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
Hello!! I desperately need help on event triggering across panels in wxPython!
I have 2 classes that inherit wx.Panel: Leftpanel & Rightpanel
Leftpanel consists of several buttons.
Rightpanel consists of a graph (i.e. using matplotlib).
I want to make the program so that pressing the button on Leftpanel will update(redraw) the graph on Rightpanel. (=event from pressing a button of a panel will trigger another function declared in another panel).
I have googled plenty of resources, but could not find any hints.
Any help would be greatly appreciated! Thanks!
I have 2 classes that inherit wx.Panel: Leftpanel & Rightpanel
Leftpanel consists of several buttons.
Rightpanel consists of a graph (i.e. using matplotlib).
I want to make the program so that pressing the button on Leftpanel will update(redraw) the graph on Rightpanel. (=event from pressing a button of a panel will trigger another function declared in another panel).
I have googled plenty of resources, but could not find any hints.
Any help would be greatly appreciated! Thanks!
sample code will help explain more. Also search for something like calling one method from another place in this forum.
What I know is you use their common parent as reference (SB can correct me if I'm wrong!)
What I know is you use their common parent as reference (SB can correct me if I'm wrong!)
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
•
•
Join Date: Nov 2008
Posts: 2
Reputation:
Solved Threads: 0
Thanks for the reply. Here I'm attaching my code.
Explanation:
LeftPanel has a button which if pressed, will call the event handler on_button described in another class (RightPanel).
The question is:
How do you make a program which has one button in a panel(=left panel) which calls to a function in another panel(=right panel)?
The purpose of doing this is that I want to make a program that has 2 panels: one showing only buttons & textboxes and the other one showing a graph. Whenever the user changes a value in boxes/buttons in left panel, the graph in the right panel also changes.
When executing the program below I got an error:
TypeError: unbound method on_button() must be called with RightPanel instance as first argument (got CommandEvent instance instead)
Help would be greatly appreaciated! Thank you guys!
Explanation:
LeftPanel has a button which if pressed, will call the event handler on_button described in another class (RightPanel).
The question is:
How do you make a program which has one button in a panel(=left panel) which calls to a function in another panel(=right panel)?
The purpose of doing this is that I want to make a program that has 2 panels: one showing only buttons & textboxes and the other one showing a graph. Whenever the user changes a value in boxes/buttons in left panel, the graph in the right panel also changes.
When executing the program below I got an error:
TypeError: unbound method on_button() must be called with RightPanel instance as first argument (got CommandEvent instance instead)
Help would be greatly appreaciated! Thank you guys!
python Syntax (Toggle Plain Text)
import wx class RightPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent) def on_button(self, event): self.calculate() def calculate(self): # Another calculation here print 1+1 class LeftPanel(wx.Panel): def __init__(self, parent): wx.Panel.__init__(self, parent) # A Button self.button = wx.Button(self, -1, 'Calculate!') # If the button is pressed, call on_button on the other class self.Bind(wx.EVT_BUTTON, RightPanel.on_button, self.button) class Frame(wx.Frame): def __init__(self): wx.Frame.__init__(self, None, -1, "Testing") self.left_panel = LeftPanel(self) self.right_panel = RightPanel(self) # Panel sizer self.panelsizer = wx.BoxSizer(wx.HORIZONTAL) self.panelsizer.Add(self.left_panel, 0, wx.LEFT | wx.TOP | wx.EXPAND) self.panelsizer.Add(self.right_panel, 1, wx.LEFT | wx.TOP | wx.EXPAND) self.SetSizer(self.panelsizer) self.panelsizer.Fit(self) if __name__ == '__main__': app = wx.PySimpleApp() app.frame = Frame() app.frame.Show() app.MainLoop()
![]() |
Other Threads in the Python Forum
- Previous Thread: Python bindings fo lame!
- Next Thread: Class interaction
| Thread Tools | Search this Thread |
abrupt alarm ansi anti approximation assignment avogadro backend beginner binary bluetooth calculator character cmd code customdialog cx-freeze data decimals dictionaries dictionary directory dynamic error examples exe file float format function gnu graphics gui halp heads homework http ideas import input java launcher leftmouse line linux list lists loop module mouse number numbers output parsing path pointer port prime programming progressbar projects push py2exe pygame pyglet pyqt python random recursion schedule screensaverloopinactive script scrolledtext sqlite statistics string strings sudokusolver sum table terminal text thread threading time tlapse tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable ventrilo wikipedia write wxpython xlib






