I would like to duplicate column headings in my first python GUI. I have tried the following
bfont = wx.Font(10,wx.DEFAULT,wx.NORMAL,wx.BOLD)
angle = wx.StaticText(panel,label="Angle")
angle.SetFont(bfont)
count_c = wx.StaticText(panel,label="Counts (C)")
count_c.SetFont(bfont)
count_u = wx.StaticText(panel,label="Counts (U)")
count_u.SetFont(bfont)
fgs.AddMany([(angle),(count_c), (count_u),
(angle),(count_c), (count_u)])
vbox.Add(fgs, proportion=1,flag=wx.ALL|wx.EXPAND,border=5)
However this only shows me the second set of headers. How can this be done?
You cannot add the same widget to two different locations. Instead, you'll have to create separate widgets for each row. Since you want the same thing on each row, you can use a loop:
import wx
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
bfont = wx.Font(10,wx.DEFAULT,wx.NORMAL,wx.BOLD)
vbox = wx.BoxSizer(wx.VERTICAL)
fgs = wx.FlexGridSizer(rows=2, cols=3, vgap=5, hgap=5)
# add two rows of widgets to the sizer
widgets = []
for i in range(2):
angle = wx.StaticText(self,label="Angle")
angle.SetFont(bfont)
widgets.append(angle)
count_c = wx.StaticText(self,label="Counts (C)")
count_c.SetFont(bfont)
widgets.append(count_c)
count_u = wx.StaticText(self,label="Counts (U)")
count_u.SetFont(bfont)
widgets.append(count_u)
fgs.AddMany(widgets)
vbox.Add(fgs, proportion=1,flag=wx.ALL|wx.EXPAND,border=5)
self.SetSizer(vbox)
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Test")
panel = MyPanel(self)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()
Related
In the following example the scrollbar disappears after using the calculating button, although the layout function was called. If you manually resize the frame it reappears. This behavior occurs only under windows, in linux the scrollbar functions as it should.
To fix it I tried the functions refresh() and update() (in layout funtion of class GUI_Diagrams_GHL) - but it didn't help.
I tried to reduce my application to this minmal working example:
# -*- coding: utf-8 -*-
import wx
from wx.lib.pubsub import pub
import wx.lib.scrolledpanel as scrolled
import matplotlib
matplotlib.use('WXAgg')
from matplotlib.figure import Figure
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigCanvas
class MainWindow(wx.Frame):
'''Frame that contains pretty much everything'''
def __init__(self,*args,**kwargs):
'''Constructor'''
super(MainWindow,self).__init__(*args,**kwargs)
self.panel = wx.Panel(self)
notebook = Notebook(self.panel)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(notebook,1, wx.ALL|wx.EXPAND,4)
self.panel.SetSizerAndFit(sizer)
self.panel.Layout()
class Notebook(wx.Notebook):
def __init__(self, parent):
wx.Notebook.__init__(self, parent, id=wx.ID_ANY, style = wx.BK_DEFAULT)
tabTwo = GUI_Input_GHL(self)
self.AddPage(tabTwo, 'Input')
tabThree = GUI_Diagrams_GHL(self)
self.AddPage(tabThree, 'Diagrams')
class GUI_Input_GHL(scrolled.ScrolledPanel):
"""This panel contains the input fields for basic data."""
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent=parent, id=wx.ID_ANY)
self.label_1 = wx.StaticText(self,-1,label=u'Label 1')
self.button2 = wx.Button(self,-1,label=u'Start')
self.Bind(wx.EVT_BUTTON, self.StartCalc, self.button2)
self.layout()
def layout(self):
sizer = wx.GridBagSizer()
sizer.Add(self.button2, (8,0),(2,3), flag =wx.EXPAND)
sizer.Add(self.label_1, (0,0),flag=wx.ALIGN_CENTER_VERTICAL)
self.SetAutoLayout(1)
self.SetupScrolling()
self.SetSizerAndFit(sizer)
def StartCalc(self,event):
pub.sendMessage('GUI_Diagrams_Listener', message = 'test')
class GUI_Diagrams_GHL(scrolled.ScrolledPanel):
"""This panel contains diagrams"""
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent=parent, id=wx.ID_ANY)
self.parent = parent
self.fig1 = Figure()
self.fig6 = Figure()
self.canvas1 = FigCanvas(self,-1,self.fig1)
self.axes1 = self.fig1.add_subplot(111)
self.canvas6 = FigCanvas(self,-1,self.fig6)
self.axes6 = self.fig6.add_subplot(111)
self.dia_R_hat_SetValues('test')
self.dia_theta_SetValues('test')
self.layout()
pub.subscribe(self.diagrams_SetValues, "GUI_Diagrams_Listener")
def layout(self):
sizer = wx.GridBagSizer()
sizer.Add(self.canvas1, (1,0), (12,12), wx.EXPAND)
sizer.Add(self.canvas6, (53,0), (12,12), wx.EXPAND)
## I guess here is the problem somewhere:
self.SetSizerAndFit(sizer)
self.SetAutoLayout(1)
self.SetupScrolling()
#self.Fit()
#self.Layout()
#self.FitInside()
#self.AlwaysShowScrollbars(True,True)
#self.Refresh()
#self.Update()
#self.parent.SetSize(self.parent.GetSize())
def diagrams_SetValues(self, message):
self.Output = message
self.dia_R_hat_SetValues(message)
self.dia_theta_SetValues(message)
self.layout()
def dia_R_hat_SetValues(self, Output):
self.axes1.clear()
self.axes1.plot(range(15),range(15), 'r-', linewidth = 2)
self.canvas1.draw()
def dia_theta_SetValues(self, Output):
self.axes6.clear()
self.axes6.plot(range(5),'k')
self.axes6.set_title(r"Absolute Temperature")
self.canvas6.draw()
if __name__ == '__main__':
app = wx.App()
frame = MainWindow(None, -1, 'MyApp')
frame.Show()
app.MainLoop()
I've figured it out myself :)
If you call the layout function of the main panel ('MainWindow.panel.Layout()') after updating the diagrams/in the layout of the diagram class, the whole panel refreshes and
the Scrollbars reappear. So a 'parent.parent.Layout()' worked for me in this case.
Any other suggestions/solutions?
I have a list generated using wxListCtrl where it has three coloumns. The data generated when the list updates is in need to use in the other part of my code.Can any one please tell me how could i get the all values of an item of all 3 coloumns in the list?
My list is as below...
self.list_ctrl = wx.ListCtrl(self.panel, size=(565,150),pos=(15,20),style=wx.LC_REPORT | wx.BORDER_SUNKEN)
self.name=self.list_ctrl.InsertColumn(0, 'Task Name',width=189)
self.date=self.list_ctrl.InsertColumn(1, 'Run ',width=189)
self.status=self.list_ctrl.InsertColumn(2, 'Status', width=187
self.index=0
where the items are generated using..
Taskname=self.list_ctrl.InsertStringItem(self.index,task)
Taskdate=self.list_ctrl.SetStringItem(self.index, 1,strftime("%d-%m-%Y", gmtime()))
Tasktime=self.list_ctrl.SetStringItem(self.index,2,datetime.now().strftime('%H:%M:%S'))
I can able to get the name of the item i.e, 'self.name' which is under 1st coloumn using
name=self.list_ctrl.GetItemText(self.name)
But 'self.date' and 'self.time' are returning the int type values.How can i get the date and time in the variable 'Taskdate' and 'Tasktime' respectively?
There are a couple of ways to do this. The simplest (in my opinion) is to associate objects with each row, but we'll do it the "hard" way first:
import wx
########################################################################
class MyForm(wx.Frame):
#----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "List Control Tutorial")
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY)
self.index = 0
self.list_ctrl = wx.ListCtrl(panel, size=(-1,100),
style=wx.LC_REPORT
|wx.BORDER_SUNKEN
)
self.list_ctrl.InsertColumn(0, 'Subject')
self.list_ctrl.InsertColumn(1, 'Due')
self.list_ctrl.InsertColumn(2, 'Location', width=125)
btn = wx.Button(panel, label="Add Line")
btn2 = wx.Button(panel, label="Get Data")
btn.Bind(wx.EVT_BUTTON, self.add_line)
btn2.Bind(wx.EVT_BUTTON, self.getColumn)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5)
sizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
sizer.Add(btn2, 0, wx.ALL|wx.CENTER, 5)
panel.SetSizer(sizer)
#----------------------------------------------------------------------
def add_line(self, event):
line = "Line %s" % self.index
self.list_ctrl.InsertStringItem(self.index, line)
self.list_ctrl.SetStringItem(self.index, 1, "01/19/2010")
self.list_ctrl.SetStringItem(self.index, 2, "USA")
self.index += 1
#----------------------------------------------------------------------
def getColumn(self, event):
""""""
count = self.list_ctrl.GetItemCount()
cols = self.list_ctrl.GetColumnCount()
for row in range(count):
for col in range(cols):
item = self.list_ctrl.GetItem(itemId=row, col=col)
print item.GetText()
#----------------------------------------------------------------------
# Run the program
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm()
frame.Show()
app.MainLoop()
This is slightly modified from an earlier answer to a similar question. Anyway, let's take a look at how to use objects instead:
import wx
########################################################################
class Car(object):
""""""
#----------------------------------------------------------------------
def __init__(self, make, model, year, color="Blue"):
"""Constructor"""
self.make = make
self.model = model
self.year = year
self.color = color
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
rows = [Car("Ford", "Taurus", "1996"),
Car("Nissan", "370Z", "2010"),
Car("Porche", "911", "2009", "Red")
]
self.list_ctrl = wx.ListCtrl(self, size=(-1,100),
style=wx.LC_REPORT
|wx.BORDER_SUNKEN
)
self.list_ctrl.Bind(wx.EVT_LIST_ITEM_SELECTED, self.onItemSelected)
self.list_ctrl.InsertColumn(0, "Make")
self.list_ctrl.InsertColumn(1, "Model")
self.list_ctrl.InsertColumn(2, "Year")
self.list_ctrl.InsertColumn(3, "Color")
index = 0
self.myRowDict = {}
for row in rows:
self.list_ctrl.InsertStringItem(index, row.make)
self.list_ctrl.SetStringItem(index, 1, row.model)
self.list_ctrl.SetStringItem(index, 2, row.year)
self.list_ctrl.SetStringItem(index, 3, row.color)
self.myRowDict[index] = row
index += 1
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.list_ctrl, 0, wx.ALL|wx.EXPAND, 5)
self.SetSizer(sizer)
#----------------------------------------------------------------------
def onItemSelected(self, event):
""""""
currentItem = event.m_itemIndex
car = self.myRowDict[currentItem]
print car.make
print car.model
print car.color
print car.year
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, wx.ID_ANY, "List Control Tutorial")
panel = MyPanel(self)
self.Show()
#----------------------------------------------------------------------
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
app.MainLoop()
Here we create a list of Car objects and we use dot-notation to add properties of the class to the ListCtrl. Then when we select an item from the list, we grab the currently selected item from the event object and look it up using a dictionary. Not exactly simple, but I rather like it. You can read more about it along with other tips and tricks here.
However, I think the best solution is to just use ObjectListView (a ListCtrl wrapper) that makes the rows into true objects and allows much easier access to their values, as well as bringing in a bunch of other enhancements. Sadly it's not a part of the normal wxPython distribution as of yet, but it's easy to add from PyPI. You can read more about it in this article from blog too!
self.btid = 0
self.btarray = []
self.btarray.append("x")#so that the buttons are appended according to their ids
self.bmt = wx.BitmapButton(panel, btid, pic, pos=(50,50))
self.btarray.append(self.bmt)
self.btid += 1
I create multiple buttons using the same code. How do I retrieve an individual buttons' ID later on?
Thanks in advance,
Swayam
GetId is the method to get the Id of an object.
So you can write:
id_of_button_n = button_n.GetId()
However in your case, this is not neccessary because you already stored the ids as the keys of the dictionary self.btarray !
Here's a quick and dirty script that will show you how to get button ids and labels. I'm using normal wx.Button objects since there's no good way to include images for bitmap buttons on Stack:
import random
import wx
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent=parent)
mainSizer = wx.BoxSizer(wx.VERTICAL)
i = random.choice(range(5, 10))
for index, item in enumerate(range(i)):
num = index + 1
btn = wx.Button(self, label="Button %s" % num)
btn.Bind(wx.EVT_BUTTON, self.onClick)
mainSizer.Add(btn, 0, wx.ALL|wx.CENTER, 5)
self.SetSizer(mainSizer)
#----------------------------------------------------------------------
def onClick(self, event):
""""""
btn = event.GetEventObject()
print "%s id => %s" % (btn.GetLabel(), btn.GetId())
########################################################################
class MainFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Random Buttons", size=(1024, 768))
panel = MyPanel(self)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
frame = MainFrame()
app.MainLoop()
I want to make a game in wxPython (no other modules) and I want to make it so that you can enter some values in popup screens before the game starts, and then the game will be drawn on a canvas which in turn is drawn on a panel, which is bound to the main game.
I made the gamescreen with all fancy stuff (works solo)
I made the input screens
But I cannot link them.
How do I start the game so it will open a dialog box, then on the closure of it open another one, and then open the game ?
I tried the following, but it will not open my canvas:
# makes a game by showing 2 dialogs
# after dialogs have been answered, starts the game by drawing the canvas.
# imports
import wx
import Speelveld3
# globals
SCRWIDTH = 950
SCRHEIGHT = 700
# dialogbox class
class MyDialog1(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent)
self.username = wx.TextCtrl(self)
self.okButton = wx.Button(self, wx.ID_OK, "OK")
class MyDialog2(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent)
self.canvasWidth = wx.TextCtrl(self)
self.okButton = wx.Button(self, wx.ID_OK, "OK")
# main class
class Game(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, title='My game', size=(SCRWIDTH, SCRHEIGHT))
self.username = ""
self.canvasWidth = 10
# hide the frame for now
self.Hide()
def OnInit(self):
#Make your dialogs
dlg1 = MyDialog1(self)
#if the user pressed "OK" (i.e. NOT "Cancel" or any other button you might add)
if dlg1.ShowModal() == wx.ID_OK:
#get the username from the dialog
self.username = dlg1.username.GetValue()
#clean up the dialog (AFTER you get the username)
dlg1.Destroy()
dlg2 = MyDialog2(self)
#if the user pressed "OK" (i.e. NOT "Cancel" or any other button you might add)
if dlg2.ShowModal() == wx.ID_OK:
#get the username from the dialog
self.canvasWidth = dlg2.canvasWidth.GetValue()
#clean up the dialog (AFTER you get the username)
dlg2.Destroy()
# Now that you have your settings, Make the gameboard
# THIS PART IS STILL BROKEN!
# I can paste the whole board class (structure of it is taken from the tetris tutorial)
# but that seems a bit much tbh...
self.gameBoard = Board.Board(self)
self.gameBoard = SetFocus()
self.gameBoard.start()
self.Centre()
self.Show(True) #show the frame
if __name__ == '__main__':
# how can I start the game here?
app = wx.App()
frame = Game()
board = Speelveld3.Speelveld(frame)
board.start()
frame.Show()
app.MainLoop()
You've double posted, and the lack of any wx.Dialog in your sample code suggests to me that you haven't even looked at a tutorial yet, but I will give you the benefit of the doubt.
First, if you want to return information from a dialog, the easiest way is to define a custom dialog. Define a new class that inherits from wx.Dialog and then set it up just like you would a normal panel or a frame. It seems to me that you will need two of these. They'll look something like this:
class MyDialog1(wx.Dialog):
def __init__(self, parent):
wx.Dialog.__init__(self, parent)
self.username = wx.TextCtrl(self) #this is where users will enter their username
self.okButton = wx.Button(self, wx.ID_OK, "OK") #Note that I'm using wx.ID_OK. This is important
Now, for the logic you want. Pretty much every object in wxPython that you actually see has the functions Show() and Hide() (API here). You don't want to show your frame until AFTER the dialogs are finished, so in your __init__(), call Hide(). I'm also initializing a variable, username, which is where I will store the data from my dialog.
class Game(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(SCRWIDTH, SCRHEIGHT))
self.username = ""
self.Hide() #don't show the frame just yet
#self.Hide() is the exact same as self.Show(False)
Now, for your dialogs. Like Mike Driscoll suggested, you call your dialogs BEFORE making your canvas. wx.Dialogs are launched using ShowModal(). By setting the ID of self.okButton to the constant wx.ID_OK, wxPython recognizes that the dialog should be closed after the button in clicked. You should also be aware of wx.ID_CANCEL.
def OnInit(self):
#Make your dialogs
dlg1 = MyDialog1(self)
if dlg1.ShowModal() == wx.ID_OK:
#if the user pressed "OK" (i.e. NOT "Cancel" or any other button you might add)
self.username = dlg1.username.GetValue() #get the username from the dialog
dlg1.Destroy() #clean up the dialog (AFTER you get the username)
#do this again for your second dialog
#Now that you have your settings, Make the gameboard
self.gameBoard = Board.Board(self)
self.gameBoard = SetFocus()
self.gameBoard.start()
self.Centre()
self.Show(True) #show the frame
In your OnInit you just need to call your dialogs and show them modally BEFORE you create your Board instance. Then it should work correctly.
EDIT (6-28-12): Here's some code:
import wx
########################################################################
class MyDlg(wx.Dialog):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Dialog.__init__(self, None, title="I'm a dialog!")
lbl = wx.StaticText(self, label="Hi from the panel's init!")
btn = wx.Button(self, id=wx.ID_OK, label="Close me")
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(lbl, 0, wx.ALL, 5)
sizer.Add(btn, 0, wx.ALL, 5)
self.SetSizer(sizer)
########################################################################
class MyPanel(wx.Panel):
""""""
#----------------------------------------------------------------------
def __init__(self, parent):
"""Constructor"""
wx.Panel.__init__(self, parent)
# show a custom dialog
dlg = MyDlg()
dlg.ShowModal()
dlg.Destroy()
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, evt):
pdc = wx.PaintDC(self)
try:
dc = wx.GCDC(pdc)
except:
dc = pdc
rect = wx.Rect(0,0, 100, 100)
for RGB, pos in [((178, 34, 34), ( 50, 90)),
(( 35, 142, 35), (110, 150)),
(( 0, 0, 139), (170, 90))
]:
r, g, b = RGB
penclr = wx.Colour(r, g, b, wx.ALPHA_OPAQUE)
brushclr = wx.Colour(r, g, b, 128) # half transparent
dc.SetPen(wx.Pen(penclr))
dc.SetBrush(wx.Brush(brushclr))
rect.SetPosition(pos)
dc.DrawRoundedRectangleRect(rect, 8)
########################################################################
class MyFrame(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Example frame")
# show a MessageDialog
style = wx.OK|wx.ICON_INFORMATION
dlg = wx.MessageDialog(parent=None,
message="Hello from the frame's init",
caption="Information", style=style)
dlg.ShowModal()
dlg.Destroy()
# create panel
panel = MyPanel(self)
if __name__ == "__main__":
app = wx.App(False)
frame = MyFrame()
frame.Show()
app.MainLoop()
I'm new to Python and WX. I created a simple test dialog shown below that prompts the user with a combobox. I would like to capture the value from the combox in my main program. How do I call it from my main program?
This is how I was purposing to call it that displays the dialog but does not currently capture the value from the combobox:
import highlight
highlight.create(self).Show(True)
a = highlight.OnComboBox1Combobox(self)
print a
The name of the Dialog file is "highlight". Below is the code:
#Boa:Dialog:Dialog2
import wx
def create(parent):
return Dialog2(parent)
[wxID_DIALOG2, wxID_DIALOG2COMBOBOX1, wxID_DIALOG2STATICTEXT1,
] = [wx.NewId() for _init_ctrls in range(3)]
class Dialog2(wx.Dialog):
def _init_ctrls(self, prnt):
# generated method, don't edit
wx.Dialog.__init__(self, id=wxID_DIALOG2, name='', parent=prnt,
pos=wx.Point(264, 140), size=wx.Size(400, 485),
style=wx.DEFAULT_DIALOG_STYLE, title='Dialog2')
self.SetClientSize(wx.Size(384, 447))
self.comboBox1 = wx.ComboBox(choices=['test1', 'test2'],
id=wxID_DIALOG2COMBOBOX1, name='comboBox1', parent=self,
pos=wx.Point(120, 16), size=wx.Size(130, 21), style=0,
value=u'wining\n')
self.comboBox1.SetToolTipString(u'comboBox1')
self.comboBox1.SetLabel(u'wining\n')
self.comboBox1.Bind(wx.EVT_COMBOBOX, self.OnComboBox1Combobox,
id=wxID_DIALOG2COMBOBOX1)
self.staticText1 = wx.StaticText(id=wxID_DIALOG2STATICTEXT1,
label=u'test', name='staticText1', parent=self, pos=wx.Point(88,
16), size=wx.Size(19, 13), style=0)
def __init__(self, parent):
self._init_ctrls(parent)
##print get_selection
##print get_selection1
def OnComboBox1Combobox(self, event):
get_selection = self.comboBox1.GetValue()
return get_selection
There are lots of dialog examples out there. Here are a couple:
The Dialogs of wxPython (Part 1 of 2)
http://zetcode.com/wxpython/dialogs/
Basically, all you need to do is instantiate your dialog, show it and then before you close it, extract the value. The typical way to do it is something like this:
myDlg = MyDialog()
res = myDlg.ShowModal()
if res == wx.ID_OK:
value = myDlg.myCombobox.GetValue()
myDlg.Destroy()
Update: Here's a more full-fledged example:
import wx
########################################################################
class MyDialog(wx.Dialog):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Dialog.__init__(self, None, title="Dialog")
self.comboBox1 = wx.ComboBox(self,
choices=['test1', 'test2'],
value="")
okBtn = wx.Button(self, wx.ID_OK)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.comboBox1, 0, wx.ALL|wx.CENTER, 5)
sizer.Add(okBtn, 0, wx.ALL|wx.CENTER, 5)
self.SetSizer(sizer)
########################################################################
class MainProgram(wx.Frame):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Frame.__init__(self, None, title="Main Program")
panel = wx.Panel(self)
btn = wx.Button(panel, label="Open dialog")
btn.Bind(wx.EVT_BUTTON, self.onDialog)
self.Show()
#----------------------------------------------------------------------
def onDialog(self, event):
""""""
dlg = MyDialog()
res = dlg.ShowModal()
if res == wx.ID_OK:
print dlg.comboBox1.GetValue()
dlg.Destroy()
if __name__ == "__main__":
app = wx.App(False)
frame = MainProgram()
app.MainLoop()