How to scroll Panel with GridBagSizer in wxPython - python

I need to make a Panel scrollable. I've used GridBagSizer
Code:
import wx
class MyFrame( wx.Frame ):
def __init__( self, parent, ID, title ):
wx.Frame.__init__( self, parent, ID, title, wx.DefaultPosition, wx.Size( 400, 300 ) )
self.InitUI()
self.Center()
self.Show()
def InitUI(self):
MPanel = wx.Panel(self)
GridBag = wx.GridBagSizer(2, 2)
CO = ["RED", "BLUE"]
for i in range(10):
X = wx.StaticText(MPanel, size=(50,50), style=wx.ALIGN_CENTER, label="")
X.SetBackgroundColour(CO[i%2])
GridBag.Add(X, pos=(i+1, 1), flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=1)
GridBag.AddGrowableCol(1)
MPanel.SetSizerAndFit(GridBag)
class MyApp( wx.App ):
def OnInit( self ):
self.fr = MyFrame( None, -1, "K" )
self.fr.Show( True )
self.SetTopWindow( self.fr )
return True
app = MyApp( 0 )
app.MainLoop()
How can I do this?

Try if following solution helps you:
import wx
import wx.lib.scrolledpanel as scrolled
class MyPanel(scrolled.ScrolledPanel):
def __init__(self, parent):
scrolled.ScrolledPanel.__init__(self, parent, -1)
self.SetAutoLayout(1)
self.SetupScrolling()
Now Instead of using MPanel=wx.Panel(self), use `MPanel = MyPanel(self) and rest of your code will remain as is.
Below is the modified code:
class MyFrame( wx.Frame ):
def __init__( self, parent, ID, title ):
wx.Frame.__init__( self, parent, ID, title, wx.DefaultPosition, wx.Size( 400, 300 ) )
self.InitUI()
self.Center()
self.Show()
def InitUI(self):
MPanel = MyPanel(self)
GridBag = wx.GridBagSizer(2, 2)
CO = ["RED", "BLUE"]
for i in range(10):
X = wx.StaticText(MPanel, size=(50,50), style=wx.ALIGN_CENTER, label="")
X.SetBackgroundColour(CO[i%2])
GridBag.Add(X, pos=(i+1, 1), flag=wx.EXPAND|wx.LEFT|wx.RIGHT, border=1)
GridBag.AddGrowableCol(1)
MPanel.SetSizerAndFit(GridBag)
class MyApp( wx.App ):
def OnInit( self ):
self.fr = MyFrame( None, -1, "K" )
self.fr.Show( True )
self.SetTopWindow( self.fr )
return True
app = MyApp( 0 )
app.MainLoop()

Related

Wxpython Phoenix - Multiple OnDropFiles boxes with TABS

I have a python 3 (wxpython phoenix) app which has two TABs, each TAB has a OnDropFiles box, but I just can't get it working. I have a simple stripped down example below, which should print the file URL on each drop, but not working, if someone could show a working example please, or point me in the right direcion, I would be very gratefull.
I'm using Python 3.10.5 and wxpython 4.2.
import wx
class ScrolledWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(510, 330), style=wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER |
wx.MAXIMIZE_BOX))
run_params = {}
self.tabbed = wx.Notebook(self, -1, style=(wx.NB_TOP))
self.filePrep = PrepFile(self.tabbed, self, run_params)
self.fileCheck = CheckFile(self.tabbed, self, run_params)
self.tabbed.AddPage(self.filePrep, "File Prep")
self.tabbed.AddPage(self.fileCheck, "File Check")
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.switchSize)
self.Centre()
self.Show()
def switchSize(self, e):
page = self.tabbed.GetPageText(self.tabbed.GetSelection())
if page == 'File Prep':
self.SetSize((510, 330))
elif page == 'File Check':
self.SetSize((510, 510))
self.fileCheck.setSubmissionDrop(self)
class PrepFile(wx.Panel):
def __init__(self, parent, frame, run_params):
wx.Panel.__init__(self, parent)
self.run_params = run_params
self.parent = parent
self.frame = self
self.selectedFiles = ""
outputtxt3 = '''Drag and Drop files'''
wx.StaticText(self, -1, outputtxt3, pos=(25, 180), style=wx.ALIGN_CENTRE)
self.drop_target = MyFileDropTarget(self)
self.SetDropTarget(self.drop_target)
self.tc_files = wx.TextCtrl(self, wx.ID_ANY, pos=(28, 200), size=(360, 25))
self.tc_files.SetFocus()
self.Show()
def setSubmissionDrop(self, dropFiles):
"""Called by the FileDropTarget when files are dropped"""
print(dropFiles)
self.tc_files.SetValue(','.join(dropFiles))
self.selectedFiles = dropFiles
class CheckFile(wx.Panel):
def __init__(self, parent, frame, run_params):
wx.Panel.__init__(self, parent)
self.run_params = run_params
self.parent = parent
self.frame = self
self.selectedFiles = ""
wx.StaticText(self, -1, '''Drag and Drop files''', pos=(25, 10), style=wx.ALIGN_CENTRE)
self.drop_target = MyFileDropTarget(self)
self.SetDropTarget(self.drop_target)
self.tc_files = wx.TextCtrl(self, wx.ID_ANY, pos=(25, 30), size=(302, 25))
self.tc_files.SetFocus()
self.Show()
def setSubmissionDrop(self, dropFiles):
"""Called by the FileDropTarget when files are dropped"""
print(dropFiles)
self.selectedFiles = dropFiles
class MyFileDropTarget(wx.FileDropTarget):
""""""
def __init__(self, window):
wx.FileDropTarget.__init__(self)
self.window = window
def OnDropFiles(self, x, y, filenames):
print(filenames)
self.window.setSubmissionDrop(filenames)
return True
app = wx.App()
ScrolledWindow(None, -1, 'File Prep ')
app.MainLoop()
We want this to be event driven, so you should define an event, from wx.lib.newevent.
I assume you want the drop zone to be the textctrl not the whole panel, so it's that that needs to be set as the target.
BIND the event.
In the FileDropTarget class we define the event and fire it.
In each drop event callback, we accept the event as a parameter and unpack whatever we packed into the event.
One last thing, in this case, you are getting back a list.
It's simple but every time you decide to use it, it trips you up, I don't know why.
import wx
import wx.lib.newevent
drop_event, EVT_DROP_EVENT = wx.lib.newevent.NewEvent()
class ScrolledWindow(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, id, title, size=(510, 330), style=wx.DEFAULT_FRAME_STYLE & ~ (wx.RESIZE_BORDER |
wx.MAXIMIZE_BOX))
run_params = {}
self.tabbed = wx.Notebook(self, -1, style=(wx.NB_TOP))
self.filePrep = PrepFile(self.tabbed, self, run_params)
self.fileCheck = CheckFile(self.tabbed, self, run_params)
self.tabbed.AddPage(self.filePrep, "File Prep")
self.tabbed.AddPage(self.fileCheck, "File Check")
self.Bind(wx.EVT_NOTEBOOK_PAGE_CHANGED, self.switchSize)
self.Centre()
self.Show()
def switchSize(self, e):
page = self.tabbed.GetPageText(self.tabbed.GetSelection())
if page == 'File Prep':
self.SetSize((510, 330))
elif page == 'File Check':
self.SetSize((510, 510))
class PrepFile(wx.Panel):
def __init__(self, parent, frame, run_params):
wx.Panel.__init__(self, parent)
self.run_params = run_params
self.parent = parent
self.frame = self
self.selectedFiles = ""
outputtxt3 = '''Drag and Drop files'''
wx.StaticText(self, -1, outputtxt3, pos=(25, 180), style=wx.ALIGN_CENTRE)
self.tc_files = wx.TextCtrl(self, wx.ID_ANY, pos=(28, 200), size=(360, 25))
self.drop_target = MyFileDropTarget(self)
self.tc_files.SetDropTarget(self.drop_target)
self.Bind(EVT_DROP_EVENT, self.setSubmissionDrop)
self.tc_files.SetFocus()
self.Show()
def setSubmissionDrop(self, event):
"""Called by the FileDropTarget when files are dropped"""
files = event.data
print("\nprep event", files)
self.tc_files.SetValue(','.join(files))
self.selectedFiles = files
class CheckFile(wx.Panel):
def __init__(self, parent, frame, run_params):
wx.Panel.__init__(self, parent)
self.run_params = run_params
self.parent = parent
self.frame = self
self.selectedFiles = ""
wx.StaticText(self, -1, '''Drag and Drop files''', pos=(25, 10), style=wx.ALIGN_CENTRE)
self.tc_files = wx.TextCtrl(self, wx.ID_ANY, pos=(25, 30), size=(302, 25))
self.drop_target = MyFileDropTarget(self)
self.tc_files.SetDropTarget(self.drop_target)
self.Bind(EVT_DROP_EVENT, self.setSubmissionDrop)
self.tc_files.SetFocus()
self.Show()
def setSubmissionDrop(self, event):
"""Called by the FileDropTarget when files are dropped"""
files = event.data
print("\ncheck event", files)
self.tc_files.SetValue(','.join(files))
self.selectedFiles = files
class MyFileDropTarget(wx.FileDropTarget):
""""""
def __init__(self, window):
wx.FileDropTarget.__init__(self)
self.obj = window
def OnDropFiles(self, x, y, filenames):
drp_evt = drop_event(data=filenames)
wx.PostEvent(self.obj, drp_evt)
return True
app = wx.App()
ScrolledWindow(None, -1, 'File Prep ')
app.MainLoop()

ComboCtrl with a CheckListBox popup - EVT_CHECKLISTBOX doesn't work

After my last post i found out that i can combine ComboCtrl with an Checklistbox Popup. So far so good. Now i try to figure out why EVT_CHECKLISTBOX doesn't work properly. Did i bound it the wrong way?
self.lc.Bind(wx.EVT_CHECKLISTBOX, self.OnSelect)
Also:
how do i make the popup fit the content? At the moment it is pretty huge
how do i change the Combobox that it doesnt fill the entire window anymore?
Here is my code so far:
import wx
import wx.stc
from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin
class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin):
def __init__(self, parent):
wx.ListCtrl.__init__(self, parent, wx.ID_ANY, style=wx.LC_REPORT |
wx.SUNKEN_BORDER)
CheckListCtrlMixin.__init__(self)
ListCtrlAutoWidthMixin.__init__(self)
class ListViewComboPopup(wx.ComboPopup):
def __init__(self):
wx.ComboPopup.__init__(self)
self.lc = None
def AddItem(self, txt):
self.lc.InsertItem(0, txt)
def OnSelect(self, event):
print("Working fine!")
def Init(self):
self.value = -1
self.curitem = -1
def Create(self, parent):
self.lc = CheckListCtrl(parent)
self.lc.InsertColumn(0, '', width=90)
self.lc.Bind(wx.EVT_CHECKLISTBOX, self.OnSelect)
return True
def GetControl(self):
return self.lc
def OnPopup(self):
wx.ComboPopup.OnPopup(self)
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Popup Menu Tutorial")
comboCtrl = wx.ComboCtrl(self, wx.ID_ANY, "")
popupCtrl = ListViewComboPopup()
comboCtrl.SetPopupControl(popupCtrl)
popupCtrl.AddItem("Test 1")
popupCtrl.AddItem("Test 2")
popupCtrl.AddItem("Test 3")
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm().Show()
app.MainLoop()
OnCheckItem is called by CheckListCtrlMixin.
Add a panel to the frame and set the ComboCtrl's parent as the panel
Change the ComboPopup's method GetAdjustedSize return value to alter the size
import wx
import wx.stc
from wx.lib.mixins.listctrl import CheckListCtrlMixin, ListCtrlAutoWidthMixin
class CheckListCtrl(wx.ListCtrl, CheckListCtrlMixin, ListCtrlAutoWidthMixin):
def __init__(self, parent):
wx.ListCtrl.__init__(self, parent, wx.ID_ANY, style=wx.LC_REPORT |
wx.SUNKEN_BORDER)
CheckListCtrlMixin.__init__(self)
ListCtrlAutoWidthMixin.__init__(self)
self.SetSize(-1, -1, -1, 50)
def OnCheckItem(self, index, flag):
item = self.GetItem(index)
if flag:
what = "checked"
else:
what = "unchecked"
print(f'{item.GetText()} - {what}')
class ListViewComboPopup(wx.ComboPopup):
def __init__(self):
wx.ComboPopup.__init__(self)
self.lc = None
def AddItem(self, txt):
self.lc.InsertItem(0, txt)
def Init(self):
self.value = -1
self.curitem = -1
def Create(self, parent):
self.lc = CheckListCtrl(parent)
self.lc.InsertColumn(0, '', width=90)
return True
def GetControl(self):
return self.lc
def OnPopup(self):
wx.ComboPopup.OnPopup(self)
def GetAdjustedSize(self, minWidth, prefHeight, maxHeight):
return wx.ComboPopup.GetAdjustedSize(
self, minWidth, 110, maxHeight)
class MyForm(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Popup Menu Tutorial")
panel = wx.Panel(self)
comboCtrl = wx.ComboCtrl(panel, wx.ID_ANY, "Select filter")
popupCtrl = ListViewComboPopup()
comboCtrl.SetPopupControl(popupCtrl)
popupCtrl.AddItem("Test 1")
popupCtrl.AddItem("Test 2")
popupCtrl.AddItem("Test 3")
if __name__ == "__main__":
app = wx.App(False)
frame = MyForm().Show()
app.MainLoop()

How can I resize * wx.CheckListBox* automatically in wxPython?

If the text of label for checkboxes is more than width of a wx.CheckListBox one must change its size.
The short answer is to not set the size of the CheckListBox. This will automatically set the size to the largest item. If you do set the size parameter and the text does not fit, set the style=wx.LB_HSCROLL and a horizontal slider will be created, if needed.
Below a demonstration with both versions of self.clb
import wx
class ClbView(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, None, -1, 'CheckListBox', size=(250, 200))
def createWidgets(self, list):
self.panel = wx.Panel(self, -1)
# self.clb = wx.CheckListBox(self.panel, -1, size=(100,150),choices=list,style=wx.LB_HSCROLL)
self.clb = wx.CheckListBox(self.panel, -1, choices = list)
self.btn_exit = wx.Button(self.panel, wx.ID_ANY, 'Exit')
def sizeWidgets(self):
self.vbox = wx.BoxSizer(wx.VERTICAL)
self.vbox.Add(self.clb, 0, wx.ALL|wx.CENTER, 5)
self.vbox.Add(self.btn_exit, 0, wx.CENTER)
self.panel.SetSizer(self.vbox)
self.Centre()
class ClbControl:
def __init__(self):
self.list = ['Quite a long piece of text', 'Short text', 'X']
self.createView()
def createView(self):
self.view = ClbView(None)
self.view.createWidgets(self.list)
self.view.sizeWidgets()
self.view.Show()
self.view.btn_exit.Bind(wx.EVT_BUTTON, self.onExit)
self.view.clb.Bind(wx.EVT_CHECKLISTBOX, self.onCLB )
def onCLB(self, evt):
x = int(evt.GetSelection())
print "Box ",x," Accessed"
def onExit(self, evt):
self.view.Close()
if __name__ == '__main__':
app = wx.App()
controller = ClbControl()
app.MainLoop()

wxpython - One Frame, Multiple Panels, Modularized Code

I'm working on a fairly large GUI project and am thus using wxpython to build it. I have one frame, multiple frames with their own functions and a main file that imports the gui components as well as other, external functions. I've decided to keep the gui/wxpython code different to better modularize the code.
The main question I have is how to execute the functions in the separate panels and how to make them work from my main python file.
Below is a sample of my wxpython code:
import wx
class MainFrame ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 800,600 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
bSizer1 = wx.BoxSizer( wx.VERTICAL )
self.SetSizer( bSizer1 )
self.Layout()
self.panelOne = panel_one(self)
self.panelTwo = panel_two(self)
self.panelTwo.Hide()
self.Centre( wx.BOTH )
def __del__( self ):
pass
class panel_one ( wx.Panel ):
def __init__( self, parent ):
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 800,600 ), style = wx.TAB_TRAVERSAL )
bSizer5 = wx.BoxSizer( wx.VERTICAL )
self.m_button2 = wx.Button( self, wx.ID_ANY, u"MyButton", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer5.Add( self.m_button2, 0, wx.ALL, 5 )
self.SetSizer( bSizer5 )
self.Layout()
# Connect Events
self.m_button2.Bind( wx.EVT_BUTTON, self.changeIntroPanel )
def __del__( self ):
pass
# Virtual event handlers, overide them in your derived class
def changeIntroPanel( self, event ):
event.Skip()
class panel_two ( wx.Panel ):
def __init__( self, parent ):
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 800,600 ), style = wx.TAB_TRAVERSAL )
... some code in here ...
def __del__( self ):
pass
So those are my gui components. Then, in my main file, I import it and run the gui:
import gui
class MainApp(gui.MainFrame):
def __init__(self, parent):
gui.MainFrame.__init__(self, parent)
self.panelOne = Panel1(self)
self.panelTwo = Panel2(self)
self.panelTwo.Hide()
class Panel1(gui.panel_one):
def __init__(self, parent):
gui.panel_one.__init__(self, parent)
def changeIntroPanel( self, event ):
if self.panelOne.IsShown():
self.SetTitle("Panel Two Showing")
self.PanelOne.Hide()
self.PanelTwo.Show()
else:
self.SetTitle("Panel One Showing")
self.PanelOne.Show()
self.PanelTwo.Hide()
self.Layout()
class Panel2(gui.panel_two):
def __init__(self, parent):
gui.panel_two.__init__(self, parent)
def main():
app = wx.App()
window = MainApp(None)
window.Show(True)
app.MainLoop()
if __name__ == '__main__':
main()
As you can tell, the idea is that I want to do all my implementation in my main file. How would I go about defining the functionality of my changeIntroPanel function that was first defined in panel_one? For now, the idea is to hide panelOne and show panelTwo.
I have done something similar before, but only with one frame. In that case, it was trivial since all the functions are in the MainFrame class to begin with. In that case, the code I posted would work perfectly.
Any help is appreciated. Thank you.
def OnInit(self, parent): is used for wx.App, you need def _ _init_ _(self, parent) instead.
About __init__ please check: Using inheritance in python
About difference between __init__ and OnInit please check this link
Edit:
gui.py
import wx
class MainFrame ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 800,600 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
bSizer1 = wx.BoxSizer( wx.VERTICAL )
self.SetSizer( bSizer1 )
self.Layout()
# self.panelOne = panel_one(self)
# self.panelTwo = panel_two(self)
# self.panelTwo.Hide()
self.Centre( wx.BOTH )
def __del__( self ):
pass
class panel_one ( wx.Panel ):
def __init__( self, parent ):
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 800,600 ), style = wx.TAB_TRAVERSAL )
bSizer5 = wx.BoxSizer( wx.VERTICAL )
self.m_button2 = wx.Button( self, wx.ID_ANY, u"panel 1 button", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer5.Add( self.m_button2, 0, wx.ALL, 5 )
self.SetSizer( bSizer5 )
self.Layout()
# Connect Events
self.m_button2.Bind( wx.EVT_BUTTON, self.changeIntroPanel )
def __del__( self ):
pass
# Virtual event handlers, overide them in your derived class
def changeIntroPanel( self, event ):
event.Skip()
class panel_two ( wx.Panel ):
def __init__( self, parent ):
wx.Panel.__init__ ( self, parent, id = wx.ID_ANY, pos = wx.DefaultPosition, size = wx.Size( 800,600 ), style = wx.TAB_TRAVERSAL )
bSizer5 = wx.BoxSizer( wx.VERTICAL )
self.m_button2 = wx.Button( self, wx.ID_ANY, u"panel 2 button ", wx.DefaultPosition, wx.DefaultSize, 0 )
bSizer5.Add( self.m_button2, 0, wx.ALL, 5 )
self.SetSizer( bSizer5 )
self.Layout()
# Connect Events
self.m_button2.Bind( wx.EVT_BUTTON, self.changeIntroPanel )
def __del__( self ):
pass
# Virtual event handlers, overide them in your derived class
def changeIntroPanel( self, event ):
event.Skip()
mainapp.py
import wx
import gui
class MainApp(gui.MainFrame):
def __init__(self, parent):
gui.MainFrame.__init__(self, parent)
self.panelOne = Panel1(self)
self.panelTwo = Panel2(self)
self.panelTwo.Hide()
class Panel1(gui.panel_one):
def __init__(self, parent):
gui.panel_one.__init__(self, parent)
self.parent = parent
def changeIntroPanel( self, event ):
if self.IsShown():
self.parent.SetTitle("Panel Two Showing")
self.Hide()
self.parent.panelTwo.Show()
class Panel2(gui.panel_two):
def __init__(self, parent):
gui.panel_two.__init__(self, parent)
self.parent = parent
def changeIntroPanel( self, event ):
if self.IsShown():
self.parent.SetTitle("Panel One Showing")
self.parent.panelOne.Show()
self.Hide()
def main():
app = wx.App()
window = MainApp(None)
window.Show(True)
app.MainLoop()
if __name__ == '__main__':
main()

How to add and edit time in a textctrl in wxpython?

I am developing a GUI using wxpython where i need a textctrl which selects the time .I tried with TimePickerCtrl but failed to fetch the time into the textctrl. It would be great if anyone shares a good example code which adds a time to a textctrl and can be edit the textctrl at any time.Thanks in advance.
Did you even look at the wxPython demo? It shows 3 different ways to create the picker control:
import wx
import wx.lib.masked as masked
class MyPanel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
# 12-hour format
text1 = wx.StaticText( self, -1, "12-hour format:", size=(150,-1))
self.time12 = masked.TimeCtrl( self, -1, name="12 hour control" )
h = self.time12.GetSize().height
spin1 = wx.SpinButton(
self, -1, wx.DefaultPosition, (-1,h), wx.SP_VERTICAL )
self.time12.BindSpinButton( spin1 )
self.addWidgets([text1, self.time12, spin1])
# 24-hour format
text2 = wx.StaticText( self, -1, "24-hour format:")
spin2 = wx.SpinButton(
self, -1, wx.DefaultPosition, (-1,h), wx.SP_VERTICAL )
self.time24 = masked.TimeCtrl(
self, -1, name="24 hour control", fmt24hr=True,
spinButton = spin2
)
self.addWidgets([text2, self.time24, spin2])
# No seconds\nor spin button
text3 = wx.StaticText( self, -1, "No seconds\nor spin button:")
self.spinless_ctrl = masked.TimeCtrl(
self, -1, name="spinless control",
display_seconds = False
)
self.addWidgets([text3, self.spinless_ctrl])
# set sizer
self.SetSizer(self.mainSizer)
def addWidgets(self, widgets):
sizer = wx.BoxSizer(wx.HORIZONTAL)
for widget in widgets:
if isinstance(widget, wx.StaticText):
sizer.Add(widget, 0, wx.ALL|wx.CENTER, 5),
else:
sizer.Add(widget, 0, wx.ALL, 5)
self.mainSizer.Add(sizer)
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Spinner Demo")
panel = MyPanel(self)
self.Show()
if __name__ == "__main__":
app = wx.App(False)
f = MyFrame()
app.MainLoop()

Categories