I am working with python v2.7 and wxPython v3.0 on Windows 8 OS.
(Sorry for the confusing title. I have no idea what the title should be. I shall try my best to explain my problem in detail.)
In my app I have a scrolled panel with a background image. This panel is named as mainPanel in the code snippet. This mainPanelcontains other panels named as myPanelA and myPanelB that have transparent background. These panels myPanelA and myPanelB contains sizers that are containing some buttons. PS: This is just a sample of my real world app. In my real world app I have many different panels and buttons. In this case the patches are more big and annoying. :(
Problem: When I resize my windows horizontally, some times (In my real world app it is very frequent as compared to this sample app.) I see blank patches in my App windows as shown in sample images below. How can I avoid this? It would be great if some one can test this and report if they have same problem on their machine (Just to be sure this is not Windows OS issue. I tested on Windows 7 too, it has the same problem.)
Update: Simply resize the window and scroll vertically, you'll see the patches quite often.
Sample Images: The patch is pointed by an arrow.
Code: Here is my code sample for playing around. The background image can be downloaded from here. greensquares.jpg
import wx
import wx.lib.scrolledpanel
class gui(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, None, id, title, style=wx.DEFAULT_FRAME_STYLE)
mainPanel = wx.lib.scrolledpanel.ScrolledPanel(self, -1)
mainPanel.SetupScrolling()
myImage = wx.Image('greensquares.jpg', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
myBitmap = wx.StaticBitmap(mainPanel, -1, myImage, (0, 0))
myPanelA = wx.Panel(myBitmap, -1, style=wx.TRANSPARENT_WINDOW, pos=(100,0), size=(150,150))
wx.StaticText(myPanelA, -1, ' MyPanelA ')
myButton1A = wx.Button(myPanelA, -1, size=(20,20))
myButton2A = wx.Button(myPanelA, -1, size=(20,20))
mySizerA = wx.BoxSizer(wx.HORIZONTAL)
mySizerA.Add(myButton1A, 0, wx.ALL, 20)
mySizerA.Add(myButton2A, 0, wx.ALL, 20)
myPanelA.SetSizer(mySizerA)
myPanelA.Layout()
myPanelB = wx.Panel(myBitmap, -1, style=wx.TRANSPARENT_WINDOW, pos=(100,130), size=(250,200))
wx.StaticText(myPanelB, -1, ' MyPanelB ')
myButton1B = wx.Button(myPanelB, -1, size=(20,20))
myButton2B = wx.Button(myPanelB, -1, size=(20,20))
myButton3B = wx.Button(myPanelB, -1, size=(20,20))
myButton4B = wx.Button(myPanelB, -1, size=(20,20))
mySizerB1 = wx.BoxSizer(wx.HORIZONTAL)
mySizerB1.Add(myButton1B, 0, wx.ALL, 20)
mySizerB1.Add(myButton2B, 0, wx.ALL, 20)
mySizerB1.Add(myButton3B, 0, wx.ALL, 20)
mySizerB1.Add(myButton4B, 0, wx.ALL, 20)
myButton5B = wx.Button(myPanelB, -1, size=(20,20))
myButton6B = wx.Button(myPanelB, -1, size=(20,20))
myButton7B = wx.Button(myPanelB, -1, size=(20,20))
myButton8B = wx.Button(myPanelB, -1, size=(20,20))
mySizerB2 = wx.BoxSizer(wx.HORIZONTAL)
mySizerB2.Add(myButton5B, 0, wx.ALL, 20)
mySizerB2.Add(myButton6B, 0, wx.ALL, 20)
mySizerB2.Add(myButton7B, 0, wx.ALL, 20)
mySizerB2.Add(myButton8B, 0, wx.ALL, 20)
mySizerC = wx.BoxSizer(wx.VERTICAL)
mySizerC.Add(mySizerB1)
mySizerC.Add(mySizerB2)
myPanelB.SetSizer(mySizerC)
myPanelB.Layout()
if __name__ == '__main__':
app = wx.App()
frame = gui(parent=None, id=-1, title="My-App")
frame.Show()
app.MainLoop()
Thank you for your time.
I added a Update method to your panels, which seems to have fixed the issue on my side.
import wx
import wx.lib.scrolledpanel
class gui(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, None, id, title, style=wx.DEFAULT_FRAME_STYLE)
mainPanel = wx.lib.scrolledpanel.ScrolledPanel(self, -1)
mainPanel.SetupScrolling()
myImage = wx.Image('greensquares.jpg', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
myBitmap = wx.StaticBitmap(mainPanel, -1, myImage, (0, 0))
self.myPanelA = wx.Panel(myBitmap, -1, style=wx.TRANSPARENT_WINDOW, pos=(100,0), size=(150,150))
wx.StaticText(self.myPanelA, -1, ' self.myPanelA ')
myButton1A = wx.Button(self.myPanelA, -1, size=(20,20))
myButton2A = wx.Button(self.myPanelA, -1, size=(20,20))
mySizerA = wx.BoxSizer(wx.HORIZONTAL)
mySizerA.Add(myButton1A, 0, wx.ALL, 20)
mySizerA.Add(myButton2A, 0, wx.ALL, 20)
self.myPanelA.SetSizer(mySizerA)
self.myPanelA.Layout()
self.myPanelB = wx.Panel(myBitmap, -1, style=wx.TRANSPARENT_WINDOW, pos=(100,130), size=(250,200))
wx.StaticText(self.myPanelB, -1, ' self.myPanelB ')
myButton1B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton2B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton3B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton4B = wx.Button(self.myPanelB, -1, size=(20,20))
mySizerB1 = wx.BoxSizer(wx.HORIZONTAL)
mySizerB1.Add(myButton1B, 0, wx.ALL, 20)
mySizerB1.Add(myButton2B, 0, wx.ALL, 20)
mySizerB1.Add(myButton3B, 0, wx.ALL, 20)
mySizerB1.Add(myButton4B, 0, wx.ALL, 20)
myButton5B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton6B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton7B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton8B = wx.Button(self.myPanelB, -1, size=(20,20))
mySizerB2 = wx.BoxSizer(wx.HORIZONTAL)
mySizerB2.Add(myButton5B, 0, wx.ALL, 20)
mySizerB2.Add(myButton6B, 0, wx.ALL, 20)
mySizerB2.Add(myButton7B, 0, wx.ALL, 20)
mySizerB2.Add(myButton8B, 0, wx.ALL, 20)
mySizerC = wx.BoxSizer(wx.VERTICAL)
mySizerC.Add(mySizerB1)
mySizerC.Add(mySizerB2)
self.myPanelB.SetSizer(mySizerC)
self.myPanelB.Layout()
self.Bind(wx.EVT_SIZE, self.OnResize)
def OnResize(self, e):
self.myPanelA.Update()
self.myPanelB.Update()
e.Skip()
if __name__ == '__main__':
app = wx.App()
frame = gui(parent=None, id=-1, title="My-App")
frame.Show()
app.MainLoop()
I finally found the solution. In addition to what multiphrenic has suggested I have also binded the scroll event to a the OnResize(). So, that when ever any scroll event EVT_SCROLL occurs the panels will be updated too. It is working fine on Windows7, 8 OS with python v2.7 and wxPython v3.0.
Working code:
import wx
import wx.lib.scrolledpanel
class gui(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, None, id, title, style=wx.DEFAULT_FRAME_STYLE)
mainPanel = wx.lib.scrolledpanel.ScrolledPanel(self, -1)
mainPanel.SetupScrolling()
myImage = wx.Image('greensquares.jpg', wx.BITMAP_TYPE_ANY).ConvertToBitmap()
myBitmap = wx.StaticBitmap(mainPanel, -1, myImage, (0, 0))
self.myPanelA = wx.Panel(myBitmap, -1, style=wx.TRANSPARENT_WINDOW, pos=(100,0), size=(150,150))
wx.StaticText(self.myPanelA, -1, 'self.myPanelA')
myButton1A = wx.Button(self.myPanelA, -1, size=(20,20))
myButton2A = wx.Button(self.myPanelA, -1, size=(20,20))
mySizerA = wx.BoxSizer(wx.HORIZONTAL)
mySizerA.Add(myButton1A, 0, wx.ALL, 20)
mySizerA.Add(myButton2A, 0, wx.ALL, 20)
self.myPanelA.SetSizer(mySizerA)
self.myPanelA.Layout()
self.myPanelB = wx.Panel(myBitmap, -1, style=wx.TRANSPARENT_WINDOW, pos=(100,130), size=(250,200))
wx.StaticText(self.myPanelB, -1, 'self.myPanelB')
myButton1B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton2B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton3B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton4B = wx.Button(self.myPanelB, -1, size=(20,20))
mySizerB1 = wx.BoxSizer(wx.HORIZONTAL)
mySizerB1.Add(myButton1B, 0, wx.ALL, 20)
mySizerB1.Add(myButton2B, 0, wx.ALL, 20)
mySizerB1.Add(myButton3B, 0, wx.ALL, 20)
mySizerB1.Add(myButton4B, 0, wx.ALL, 20)
myButton5B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton6B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton7B = wx.Button(self.myPanelB, -1, size=(20,20))
myButton8B = wx.Button(self.myPanelB, -1, size=(20,20))
mySizerB2 = wx.BoxSizer(wx.HORIZONTAL)
mySizerB2.Add(myButton5B, 0, wx.ALL, 20)
mySizerB2.Add(myButton6B, 0, wx.ALL, 20)
mySizerB2.Add(myButton7B, 0, wx.ALL, 20)
mySizerB2.Add(myButton8B, 0, wx.ALL, 20)
mySizerC = wx.BoxSizer(wx.VERTICAL)
mySizerC.Add(mySizerB1)
mySizerC.Add(mySizerB2)
self.myPanelB.SetSizer(mySizerC)
self.myPanelB.Layout()
self.Bind(wx.EVT_SIZE, self.OnResize)
self.Bind(wx.EVT_SCROLL, self.OnResize)
def OnResize(self, e):
self.myPanelA.Update()
self.myPanelB.Update()
e.Skip()
if __name__ == '__main__':
app = wx.App()
frame = gui(parent=None, id=-1, title="My-App")
frame.Show()
app.MainLoop()
Related
I am trying to plot 1D txt files in a part of the window created using wxpython. For this purpose, a directory selection tool was included which lists all txt files. Now, I would like to select a txt file and plot it in a panel on the right side.
Further, I am thinking to implement a button that does some operations on the data and replot again.
What I have tried is this :
import os
import wx
import numpy as np
import matplotlib
from matplotlib.backends.backend_wxagg import FigureCanvasWxAgg as FigureCanvas
from matplotlib.figure import Figure
class mainFrame (wx.Frame):
def __init__(self):
super().__init__(None, id=wx.ID_ANY, title=u" test ",
size=wx.Size(854, 698),
style=wx.DEFAULT_FRAME_STYLE | wx.TAB_TRAVERSAL)
self.SetSizeHints(wx.Size(600, -1), wx.DefaultSize)
sizer = wx.BoxSizer(wx.VERTICAL)
self.panel = MainPanel(self, style=wx.TAB_TRAVERSAL)
self.Layout()
sizer.Add(self.panel, 1, wx.EXPAND, 0)
self.SetSizer(sizer)
self.Layout()
self.Centre()
# Connect Events
self.panel.dirPicker.Bind(wx.EVT_DIRPICKER_CHANGED, self.dirPickerOnDirChanged)
self.panel.listBox.Bind(wx.EVT_LISTBOX, self.listBoxOnListBox)
# ------------ Add widget program settings
# ------------ Call Populates
self.Show()
# Virtual event handlers, override them in your derived class
def dirPickerOnDirChanged(self, event):
self.FilePath = event.GetPath()
self.populateFileList()
def populateFileList(self):
self.panel.listBox.Clear()
allFiles = os.listdir(self.FilePath)
for file in allFiles:
if file.endswith('.txt'):
self.panel.listBox.Append(file)
def listBoxOnListBox(self, event):
try:
selected_file = event.GetString()
file_address = os.path.join(self.FilePath, selected_file)
# load file
data = np.loadtxt(file_address)
# select the first column
if isinstance(data, np.ndarray):
print("\tdata is np.array")
dim = data.ndim
if dim == 2:
input1D = data[:, 0]
else:
input1D = data
print(input1D.shape)
# plot here
else:
print("\tdata is not np.array")
except: # Do not use bare except
print("Some error.")
class MainPanel(wx.Panel):
def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.FONT_11 = wx.Font(11, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL, False, "Consolas")
self.FONT_12 = wx.Font(12, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL, False, wx.EmptyString)
self.FONT_13 = wx.Font(13, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_NORMAL, False, wx.EmptyString)
self.FONT_14 = wx.Font(14, wx.FONTFAMILY_MODERN, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_BOLD, False, "Consolas")
self.FONT_16 = wx.Font(16, wx.FONTFAMILY_SCRIPT, wx.FONTSTYLE_NORMAL,
wx.FONTWEIGHT_BOLD, False, wx.EmptyString)
sizer = wx.BoxSizer(wx.VERTICAL)
quick_display = self._quick_display()
directory_sizer = self._directory_sizer()
list_box_sizer = self._list_box_sizer()
self.text_details = self._detail_input()
details_sizer = self._details_sizer()
status_sizer = self._status_sizer()
message_sizer = wx.BoxSizer(wx.VERTICAL)
message_sizer.Add(details_sizer, 1, wx.EXPAND, 5)
message_sizer.Add(status_sizer, 1, wx.EXPAND, 5)
sizer.Add(quick_display, 0, wx.EXPAND, 0)
sizer.Add(directory_sizer, 0, wx.EXPAND, 0)
sizer.Add(list_box_sizer, 1, wx.EXPAND, 0)
sizer.Add(message_sizer, 1, wx.EXPAND, 5)
self.SetSizer(sizer)
def _quick_display(self):
quick_display = wx.StaticText(self, label=u"quick display")
quick_display.Wrap(-1)
quick_display.SetFont(self.FONT_16)
return quick_display
def _directory_sizer(self):
sbSizerDir = wx.StaticBoxSizer(wx.StaticBox(self, label=u" working directory"))
self.dirPicker = wx.DirPickerCtrl(sbSizerDir.GetStaticBox(), message=u"Select a folder")
sbSizerDir.Add(self.dirPicker, 0, wx.ALL | wx.EXPAND, 5)
return sbSizerDir
def _list_box(self):
listBoxChoices = []
self.listBox = wx.ListBox(self, size=wx.Size(300, -1), choices=listBoxChoices)
self.listBox.SetMinSize(wx.Size(250, -1))
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.listBox, 1, wx.ALL, 10)
return sizer
def _plot_sizer(self):
self.panelPlot = PlotPanel(self)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.panelPlot, 1, wx.EXPAND | wx.ALL, 5)
return sizer
def _list_box_sizer(self):
file_list_sizer = self._list_box()
bSizer_plot = self._plot_sizer()
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(file_list_sizer, 1, wx.EXPAND, 0)
sizer.Add(bSizer_plot, 1, wx.EXPAND, 5)
bSizerSplitHor = wx.BoxSizer(wx.HORIZONTAL)
bSizerSplitHor.Add(sizer, 1, wx.EXPAND, 2)
bSizerSplit = wx.BoxSizer(wx.VERTICAL)
bSizerSplit.Add(bSizerSplitHor, 1, wx.EXPAND, 0)
return bSizerSplit
def _detail_label(self):
detail_label = wx.StaticText(self, label="Details")
detail_label.Wrap(-1)
detail_label.SetFont(self.FONT_14)
return detail_label
def _detail_input(self):
text_details = wx.TextCtrl(self, size=wx.Size(250, -1))
text_details.SetFont(self.FONT_11)
return text_details
def _button_sizer(self):
self.button = wx.Button(self, label=u"do some operation")
self.button.SetFont(self.FONT_13)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.button, 0, wx.ALL, 5)
return sizer
def _details_sizer(self):
detail_label = self._detail_label()
button_sizer = self._button_sizer()
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(detail_label, 0, wx.ALL, 5)
sizer.Add(self.text_details, 1, wx.EXPAND, 5)
sizer.Add(button_sizer, 1, wx.EXPAND, 5)
return sizer
def _status_sizer(self):
self.staticline3 = wx.StaticLine(self)
self.status_label = wx.StaticText(self, label=u"Status bar")
self.status_label.Wrap(-1)
self.status_label.SetFont(self.FONT_12)
self.staticline4 = wx.StaticLine(self)
self.textCtrl_status = wx.TextCtrl(self)
self.textCtrl_status.SetFont(self.FONT_11)
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(self.staticline3, 0, wx.EXPAND | wx.ALL, 5)
sizer.Add(self.status_label, 0, wx.ALL, 5)
sizer.Add(self.staticline4, 0, wx.EXPAND | wx.ALL, 5)
sizer.Add(self.textCtrl_status, 0, wx.ALL | wx.EXPAND, 5)
status_sizer = wx.BoxSizer(wx.VERTICAL)
status_sizer.Add(sizer, 1, wx.EXPAND, 5)
return status_sizer
class PlotPanel(wx.Panel):
def __init__(self, parent, *args, **kwargs):
super().__init__(parent, *args, **kwargs)
self.SetMinSize(wx.Size(100, -1))
if __name__ == "__main__":
app = wx.App(False)
frame = mainFrame()
app.MainLoop()
This creates a window as follows :
The right portion is assigned as a panel, and I not sure how to place the matplotlib plot in it. Thank you.
There are several good questions on SE probing this topic, such as Q1 and Q2; however, most are limited to the plot being shown on the main window.
wxGlade includes some wxPython / matplotlib examples. Use these as starting point.
https://github.com/wxGlade/wxGlade/tree/master/examples
I have this class which deals with listBox:
I tried to make a delete button for listBox items but it didn't work. The "deleteItem" function does now work.Without the marked parts it works good, but there is no delete option. Help someone?
class SettingProcess(wx.Frame):
itemsArr= []
# ----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Black list Proceses",size=(500, 600))
self.Centre()
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY,size=(500, 600))
self.index = 0
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
lbl_process = wx.StaticText(panel, -1, "Process name")
lbl_process.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
self.txt_processname = wx.TextCtrl(panel, size=(140, -1))
self.txt_processname.SetValue("chrome.exe")
sizer.AddMany([lbl_process, self.txt_processname])
#------------- Files ListBox -------------------------------------
global ProcessListMain
self.files_listBox = wx.ListBox(panel, -1, (12, 130), (200, 240), ProcessListMain,
wx.LB_SINGLE | wx.LB_HSCROLL | wx.LB_ALWAYS_SB | wx.LB_SORT)
self.files_listBox.SetBackgroundColour(wx.Colour(255, 255, 128))
#------------- Set event handlers ---------------------------------
m_start = wx.Button(panel, wx.ID_CLOSE, "Add")
m_start.Bind(wx.EVT_BUTTON, self.OnAddButton)
sizer.Add(m_start, 0, wx.ALL, 10)
m_close = wx.Button(panel, wx.ID_CLOSE, "Close")
m_close.Bind(wx.EVT_BUTTON, self.onExit)
sizer.Add(m_close, 0, wx.ALL, 10)
**m_delete = wx.Button(panel, wx.ID_CLOSE, "Delete")
m_delete.Bind(wx.EVT_BUTTON, self.deleteItem)
sizer.Add(m_delete, 0, wx.ALL, 10)**
panel.SetSizer(sizer)
# ----------------------------------------------------------------------
def OnAddButton(self,str):
global ProcessListMain
#print "value is "+ str(self.txt_processname.GetValue())
ProcessListMain.append(self.txt_processname.GetValue())
self.files_listBox.Set(ProcessListMain)
def onExit(self, event):
self.Destroy()
***def deleteItem(self,event):
numOfItems=self.files_listBox.GetCount()
for i in range(numOfItems):
self.itemsArr[i]=self.files_listBox.GetString()
selectedItems=self.files_listBox.GetStringSelection()
self.files_listBox.clear()
for i in numOfItems :
if self.itemsArr[i]!=selectedItems:
self.files_listBox.append( self.itemsArr[i])***
Here is the version, courtesy of Robin Dunn's comment:
Note that I have also bound the textctrl so that just filling in a process name and pressing Enter, also acts like the Add button.
import wx
class SettingProcess(wx.Frame):
# ----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Black list Processes",size=(500, 600))
self.Centre()
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY,size=(500, 600))
self.index = 0
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
lbl_process = wx.StaticText(panel, -1, "Process name")
lbl_process.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
self.txt_processname = wx.TextCtrl(panel, size=(140, -1), style=wx.TE_PROCESS_ENTER)
self.txt_processname.SetValue("chrome.exe")
self.txt_processname.Bind(wx.EVT_TEXT_ENTER, self.OnAddButton)
sizer.AddMany([lbl_process, self.txt_processname])
#------------- Files ListBox -------------------------------------
ProcessListMain = ['Process A','Process B','Process C','Process D','Process E']
self.files_listBox = wx.ListBox(panel, -1, (12, 130), (200, 240), ProcessListMain,
wx.LB_SINGLE | wx.LB_HSCROLL | wx.LB_ALWAYS_SB | wx.LB_SORT)
self.files_listBox.SetBackgroundColour(wx.Colour(255, 255, 128))
#------------- Set event handlers ---------------------------------
m_start = wx.Button(panel, -1, "Add")
m_start.Bind(wx.EVT_BUTTON, self.OnAddButton)
sizer.Add(m_start, 0, wx.ALL, 10)
m_close = wx.Button(panel, -1, "Close")
m_close.Bind(wx.EVT_BUTTON, self.onExit)
sizer.Add(m_close, 0, wx.ALL, 10)
m_delete = wx.Button(panel, -1, "Delete")
m_delete.Bind(wx.EVT_BUTTON, self.deleteItem)
sizer.Add(m_delete, 0, wx.ALL, 10)
panel.SetSizer(sizer)
# ----------------------------------------------------------------------
def OnAddButton(self,event):
Addproc = self.txt_processname.GetValue()
if Addproc:
self.files_listBox.Append(Addproc)
def onExit(self, event):
self.Destroy()
def deleteItem(self,event):
deleted_item = self.files_listBox.GetSelection()
self.files_listBox.Delete(deleted_item)
if __name__=='__main__':
app = wx.App()
frame = SettingProcess()
frame.Show()
app.MainLoop()
It's a bit more complicated than having duplicate Id's for your buttons, as I suggested earlier.
Try the following: (I have stuck with your global ProcessListMain but had to mock it up, as it isn't declared in your questions code)
import wx
class SettingProcess(wx.Frame):
itemsArr= []
# ----------------------------------------------------------------------
def __init__(self):
wx.Frame.__init__(self, None, wx.ID_ANY, "Black list Processes",size=(500, 600))
self.Centre()
# Add a panel so it looks the correct on all platforms
panel = wx.Panel(self, wx.ID_ANY,size=(500, 600))
self.index = 0
sizer = wx.FlexGridSizer(cols=2, hgap=6, vgap=6)
lbl_process = wx.StaticText(panel, -1, "Process name")
lbl_process.SetFont(wx.Font(10, wx.SWISS, wx.NORMAL, wx.BOLD))
self.txt_processname = wx.TextCtrl(panel, size=(140, -1))
self.txt_processname.SetValue("chrome.exe")
sizer.AddMany([lbl_process, self.txt_processname])
#------------- Files ListBox -------------------------------------
global ProcessListMain
ProcessListMain = ['123','456','789','1123','2123']
self.files_listBox = wx.ListBox(panel, -1, (12, 130), (200, 240), ProcessListMain,
wx.LB_SINGLE | wx.LB_HSCROLL | wx.LB_ALWAYS_SB | wx.LB_SORT)
self.files_listBox.SetBackgroundColour(wx.Colour(255, 255, 128))
#------------- Set event handlers ---------------------------------
m_start = wx.Button(panel, -1, "Add")
m_start.Bind(wx.EVT_BUTTON, self.OnAddButton)
sizer.Add(m_start, 0, wx.ALL, 10)
m_close = wx.Button(panel, -1, "Close")
m_close.Bind(wx.EVT_BUTTON, self.onExit)
sizer.Add(m_close, 0, wx.ALL, 10)
m_delete = wx.Button(panel, -1, "Delete")
m_delete.Bind(wx.EVT_BUTTON, self.deleteItem)
sizer.Add(m_delete, 0, wx.ALL, 10)
panel.SetSizer(sizer)
# ----------------------------------------------------------------------
def OnAddButton(self,event):
global ProcessListMain
Addproc = self.txt_processname.GetValue()
ProcessListMain.append(Addproc)
self.files_listBox.Set(ProcessListMain)
def onExit(self, event):
self.Destroy()
def deleteItem(self,event):
global ProcessListMain
deleted_item = self.files_listBox.GetStringSelection()
numOfItems=self.files_listBox.GetCount()
itemsArr = []
for i in range(numOfItems):
x = self.files_listBox.GetString(i)
if x != deleted_item:
itemsArr.append(x)
ProcessListMain = itemsArr
self.files_listBox.Clear()
self.files_listBox.Set(ProcessListMain)
self.files_listBox.Update()
if __name__=='__main__':
app = wx.App()
frame = SettingProcess()
frame.Show()
app.MainLoop()
I've recently started using wxPython to build a GUI and I'm trying to create the following layout:
Button1 Button2 Button3
----------------------------------------
listbox | textctrl
The buttons should have a flexible width, expanding to fill the full width of the frame with a border between them (each buttons has a width (incl. border) of 1/3 frame). Their height should be set to a height in pixels.
The listbox should fill the frame vertically and have a set width of x pixels
The textctrol should be a textbox which expands to fill the width of the frame vertically as well as horizontally.
This is the code I have:
mainPanel = wx.Panel(self, -1)
parentBox = wx.BoxSizer(wx.VERTICAL)
menubar = wx.MenuBar()
filem = wx.Menu()
menubar.Append(filem, '&File')
self.SetMenuBar(menubar)
navPanel = wx.Panel(mainPanel, -1, size=(1000, 80))
navBox = wx.BoxSizer(wx.HORIZONTAL)
newSection = wx.Button(navPanel, self.ID_NEW, 'New')
renSection = wx.Button(navPanel, self.ID_RENAME, 'Rename')
dltSection = wx.Button(navPanel, self.ID_DELETE, 'Delete')
navBox.Add(newSection, 1, wx.EXPAND | wx.ALL, 5)
navBox.Add(renSection, 1, wx.EXPAND | wx.ALL, 5)
navBox.Add(dltSection, 1, wx.EXPAND | wx.ALL, 5)
navPanel.SetSizer(navBox)
contentPanel = wx.Panel(mainPanel, -1, size=(1000, 600))
contentBox = wx.BoxSizer(wx.HORIZONTAL)
self.listbox = wx.ListBox(contentPanel, -1, size=(300, 700))
self.settings = wx.TextCtrl(contentPanel, -1)
contentBox.Add(self.listbox, 0)
contentBox.Add(self.settings, 1, wx.EXPAND | wx.ALL, 5)
contentPanel.SetSizer(contentBox)
parentBox.Add(navPanel, 0, wx.EXPAND | wx.ALL, 5)
parentBox.Add(contentPanel, 1, wx.EXPAND | wx.ALL, 5)
mainPanel.SetSizer(parentBox)
Something is going wrong since what I see is not what I expect to see, anybody who can help me out?
It is working for me, I'm on win64, python 32bit 2.7.3.3, wx '2.8.12.1 (msw-unicode)'. The full working test example is:
import wx
class testframe(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, 'some title')
mainPanel = wx.Panel(self, -1)
parentBox = wx.BoxSizer(wx.VERTICAL)
menubar = wx.MenuBar()
filem = wx.Menu()
menubar.Append(filem, '&File')
self.SetMenuBar(menubar)
navPanel = wx.Panel(mainPanel, -1, size=(1000, 80))
navBox = wx.BoxSizer(wx.HORIZONTAL)
newSection = wx.Button(navPanel, -1, 'New')
renSection = wx.Button(navPanel, -1, 'Rename')
dltSection = wx.Button(navPanel, -1, 'Delete')
navBox.Add(newSection, 1, wx.EXPAND | wx.ALL, 5)
navBox.Add(renSection, 1, wx.EXPAND | wx.ALL, 5)
navBox.Add(dltSection, 1, wx.EXPAND | wx.ALL, 5)
navPanel.SetSizer(navBox)
contentPanel = wx.Panel(mainPanel, -1, size=(1000, 600))
contentBox = wx.BoxSizer(wx.HORIZONTAL)
self.listbox = wx.ListBox(contentPanel, -1, size=(300, 700))
self.settings = wx.TextCtrl(contentPanel, -1)
contentBox.Add(self.listbox, 0, wx.ALL, 5)
contentBox.Add(self.settings, 1, wx.EXPAND | wx.ALL, 5)
contentPanel.SetSizer(contentBox)
parentBox.Add(navPanel, 0, wx.EXPAND | wx.ALL, 5)
parentBox.Add(contentPanel, 1, wx.EXPAND | wx.ALL, 5)
mainPanel.SetSizer(parentBox)
parentBox.Fit(self)
app = wx.PySimpleApp()
app.frame = testframe()
app.frame.Show()
app.MainLoop()
Notice the addition of Fit() of the main sizer, and also 5px border added to the listbox.
first, sorry for my english - im still learning. I´m a student from Germany and i learn Python.
I have a program which needs a lot of paramters for running so i build a gui by wxGlade. Now i want to get this paramters in my application. I saw some things. They used the GUI for editing a INI- File. And the application gets the paramters from these INI. But this is not what i want. I want to controll my application with the GUI.
And it is very Important that i can save my Values in the GUI (so that the User should not do everything again).
Hope you understand what i mean.
Here is my Code for the Gui (not ready but it is enough for doing the first steps)
Here is my GUI Code:
#!/usr/bin/env python
# -*- coding: UTF-8 -*-
#
# generated by wxGlade 0.6.8 (standalone edition) on Thu Apr 24 12:36:34 2014
#
import wx
# begin wxGlade: dependencies
import gettext
# end wxGlade
# begin wxGlade: extracode
# end wxGlade
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
# begin wxGlade: MyFrame.__init__
kwds["style"] = wx.DEFAULT_FRAME_STYLE
wx.Frame.__init__(self, *args, **kwds)
# Menu Bar
self.frame_3_menubar = wx.MenuBar()
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.ID_ANY, _("Beenden"), "", wx.ITEM_NORMAL)
self.frame_3_menubar.Append(wxglade_tmp_menu, _("Datei"))
wxglade_tmp_menu = wx.Menu()
self.frame_3_menubar.Append(wxglade_tmp_menu, _("Bearbeiten"))
wxglade_tmp_menu = wx.Menu()
wxglade_tmp_menu.Append(wx.ID_ANY, _("Dokumenationen"), "", wx.ITEM_NORMAL)
self.frame_3_menubar.Append(wxglade_tmp_menu, _("Hilfe"))
self.SetMenuBar(self.frame_3_menubar)
# Menu Bar end
self.frame_3_statusbarr = self.CreateStatusBar(1, 0)
self.kartei = wx.Notebook(self, wx.ID_ANY, style=0)
self.pane_all_settings = wx.Panel(self.kartei, wx.ID_ANY)
self.label_5 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Laufzeiteinstellungen"))
self.label_6 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Abrechnungsjahr"))
self.abr_jahr = wx.SpinCtrl(self.pane_all_settings, wx.ID_ANY, "", min=2000, max=2099, style=wx.SP_ARROW_KEYS | wx.TE_AUTO_URL)
self.label_7 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Abrechnungmonat"))
self.abr_monat = wx.SpinCtrl(self.pane_all_settings, wx.ID_ANY, "", min=1, max=12)
self.label_8 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Payroll"))
self.payroll = wx.ComboBox(self.pane_all_settings, wx.ID_ANY, choices=[_("Loga"), _("Sage"), _("SAP"), _("KidiCap"), _("fidelis Personal")], style=wx.CB_DROPDOWN)
self.label_1 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Mandant"))
self.mandant = wx.SpinCtrl(self.pane_all_settings, wx.ID_ANY, "1", min=0, max=999, style=wx.SP_ARROW_KEYS | wx.TE_AUTO_URL)
self.zuschlag = wx.CheckBox(self.pane_all_settings, wx.ID_ANY, _(u"Zuschl\xe4ge"))
self.fehlzeit = wx.CheckBox(self.pane_all_settings, wx.ID_ANY, _("Fehlzeiten"))
self.urlaub = wx.CheckBox(self.pane_all_settings, wx.ID_ANY, _(u"Urlaubsanspr\xfcche"))
self.soll = wx.CheckBox(self.pane_all_settings, wx.ID_ANY, _("Sollstunden"))
self.label_8_copy_1 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("ImpVar"))
self.dir_impvar = wx.TextCtrl(self.pane_all_settings, wx.ID_ANY, "")
self.label_8_copy_2 = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("ImpUbr"))
self.dir_impubr = wx.TextCtrl(self.pane_all_settings, wx.ID_ANY, "")
self.label_8_copy_1_copy = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Pfad zur ImpVar"))
self.dir_impvar_copy = wx.TextCtrl(self.pane_all_settings, wx.ID_ANY, "")
self.label_8_copy_1_copy_copy = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Pfad zur ImpUbr"))
self.dir_impvar_copy_1 = wx.TextCtrl(self.pane_all_settings, wx.ID_ANY, "")
self.label_8_copy_1_copy_copy_copy = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Ausgabeverzeichnis"))
self.dir_impvar_copy_2 = wx.TextCtrl(self.pane_all_settings, wx.ID_ANY, "")
self.button_1 = wx.Button(self.pane_all_settings, wx.ID_ANY, _("Exportieren"))
self.button_1_copy = wx.Button(self.pane_all_settings, wx.ID_ANY, _("Abbrechen"))
self.pan_loga = wx.Panel(self.kartei, wx.ID_ANY)
self.label_5_copy = wx.StaticText(self.pan_loga, wx.ID_ANY, _("Exportieren nach Loga"))
self.label_6_copy = wx.StaticText(self.pan_loga, wx.ID_ANY, _("Loga-Mandant"))
self.loga_mandant = wx.SpinCtrl(self.pan_loga, wx.ID_ANY, "1", min=0, max=1000000, style=wx.SP_ARROW_KEYS | wx.TE_AUTO_URL)
self.label_7_copy = wx.StaticText(self.pan_loga, wx.ID_ANY, _("Loga-Abrechnungskreis"))
self.loga_al = wx.SpinCtrl(self.pan_loga, wx.ID_ANY, "", min=0, max=100)
self.label_8_copy = wx.StaticText(self.pan_loga, wx.ID_ANY, _("Empty"))
self.combo_box_1_copy = wx.ComboBox(self.pan_loga, wx.ID_ANY, choices=[], style=wx.CB_DROPDOWN)
self.label_1_copy = wx.StaticText(self.pan_loga, wx.ID_ANY, _(u"Personalnummer f\xfcllen"))
self.loga_fill_pnr = wx.SpinCtrl(self.pan_loga, wx.ID_ANY, "1", min=0, max=999, style=wx.SP_ARROW_KEYS | wx.TE_AUTO_URL)
self.konv_loa = wx.CheckBox(self.pan_loga, wx.ID_ANY, _("Konvertierungslohnart"))
self.konv_fehl = wx.CheckBox(self.pan_loga, wx.ID_ANY, _("Konvertierungsfehlzeiten"))
self.zeitraum_fehl = wx.CheckBox(self.pan_loga, wx.ID_ANY, _("Zeitraum Fehlzeit"))
self.vertragsnummer = wx.CheckBox(self.pan_loga, wx.ID_ANY, _(u"Vertragsnummer ber\xfccksichtigen"))
self.notebook_2_pane_3 = wx.Panel(self.kartei, wx.ID_ANY)
self.notebook_2_pane_4 = wx.Panel(self.kartei, wx.ID_ANY)
self.notebook_2_pane_5 = wx.Panel(self.kartei, wx.ID_ANY)
self.notebook_2_pane_6 = wx.Panel(self.kartei, wx.ID_ANY)
self.notebook_2_pane_7 = wx.Panel(self.kartei, wx.ID_ANY)
self.__set_properties()
self.__do_layout()
self.Bind(wx.EVT_MENU, self.stopExport, id=wx.ID_ANY)
self.Bind(wx.EVT_BUTTON, self.startExport, self.button_1)
self.Bind(wx.EVT_BUTTON, self.stopExport, self.button_1_copy)
# end wxGlade
def __set_properties(self):
# begin wxGlade: MyFrame.__set_properties
self.SetTitle(_("TDA Export Manager 0.12"))
self.frame_3_statusbarr.SetStatusWidths([-1])
# statusbar fields
frame_3_statusbarr_fields = [_("(C) TDA-HR-Software Entwicklungs GmbH")]
for i in range(len(frame_3_statusbarr_fields)):
self.frame_3_statusbarr.SetStatusText(frame_3_statusbarr_fields[i], i)
self.payroll.SetSelection(-1)
# end wxGlade
def __do_layout(self):
# begin wxGlade: MyFrame.__do_layout
sizer_2 = wx.BoxSizer(wx.HORIZONTAL)
grid_sizer_2_copy = wx.FlexGridSizer(10, 4, 0, 0)
grid_sizer_2 = wx.FlexGridSizer(10, 4, 0, 0)
grid_sizer_2.Add(self.label_5, 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_6, 0, wx.ALL, 10)
grid_sizer_2.Add(self.abr_jahr, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_7, 0, wx.ALL, 10)
grid_sizer_2.Add(self.abr_monat, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8, 0, wx.ALL, 10)
grid_sizer_2.Add(self.payroll, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_1, 0, wx.ALL, 10)
grid_sizer_2.Add(self.mandant, 0, wx.ALL, 10)
grid_sizer_2.Add(self.zuschlag, 0, wx.ALL, 10)
grid_sizer_2.Add(self.fehlzeit, 0, wx.ALL, 10)
grid_sizer_2.Add(self.urlaub, 0, wx.ALL, 10)
grid_sizer_2.Add(self.soll, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8_copy_1, 0, wx.ALL, 10)
grid_sizer_2.Add(self.dir_impvar, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8_copy_2, 0, wx.ALL, 10)
grid_sizer_2.Add(self.dir_impubr, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8_copy_1_copy, 0, wx.ALL, 10)
grid_sizer_2.Add(self.dir_impvar_copy, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8_copy_1_copy_copy, 0, wx.ALL, 10)
grid_sizer_2.Add(self.dir_impvar_copy_1, 0, wx.ALL, 10)
grid_sizer_2.Add(self.label_8_copy_1_copy_copy_copy, 0, wx.ALL, 10)
grid_sizer_2.Add(self.dir_impvar_copy_2, 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2.Add(self.button_1, 0, wx.ALL, 10)
grid_sizer_2.Add(self.button_1_copy, 0, wx.ALL, 10)
self.pane_all_settings.SetSizer(grid_sizer_2)
grid_sizer_2_copy.Add(self.label_5_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.label_6_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.loga_mandant, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.label_7_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.loga_al, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.label_8_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.combo_box_1_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.label_1_copy, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.loga_fill_pnr, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.konv_loa, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.konv_fehl, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.zeitraum_fehl, 0, wx.ALL, 10)
grid_sizer_2_copy.Add(self.vertragsnummer, 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
grid_sizer_2_copy.Add((20, 20), 0, wx.ALL, 10)
self.pan_loga.SetSizer(grid_sizer_2_copy)
self.kartei.AddPage(self.pane_all_settings, _("Allgemeine Einstellungen"))
self.kartei.AddPage(self.pan_loga, _("Loga"))
self.kartei.AddPage(self.notebook_2_pane_3, _("Sage"))
self.kartei.AddPage(self.notebook_2_pane_4, _("SAP"))
self.kartei.AddPage(self.notebook_2_pane_5, _("KidiCap"))
self.kartei.AddPage(self.notebook_2_pane_6, _("fidelis Personal"))
self.kartei.AddPage(self.notebook_2_pane_7, _("Konvertierungsfehlzeiten"))
sizer_2.Add(self.kartei, 1, wx.EXPAND, 0)
self.SetSizer(sizer_2)
sizer_2.Fit(self)
self.Layout()
# end wxGlade
def startExport(self, event): # wxGlade: MyFrame.<event_handler>
abrjahr = self.abr_jahr.GetValue()
print abrjahr
def stopExport(self, event): # wxGlade: MyFrame.<event_handler>
self.Close()
# end of class MyFrame
if __name__ == "__main__":
gettext.install("app") # replace with the appropriate catalog name
app = wx.PySimpleApp(0)
wx.InitAllImageHandlers()
frame_3 = MyFrame(None, wx.ID_ANY, "")
app.SetTopWindow(frame_3)
frame_3.Show()
app.MainLoop()
There are ways to get the class objects and iterate over them.
But i'd suggest a restructure of the code and consider a container for your graphical elements instead, like this:
self.frames = {}
self.frames['_3_menubar'] = wx.MenuBar()
self.frames['frame_3_statusbarr'] = self.CreateStatusBar(1, 0)
self.frames['kartei'] = wx.Notebook(self, wx.ID_ANY, style=0)
self.frames['pane_all_settings'] = wx.Panel(self.kartei, wx.ID_ANY)
self.frames['label_5'] = wx.StaticText(self.pane_all_settings, wx.ID_ANY, _("Laufzeiteinstellungen"))
#... Etc etc, the rest of the objects
# And do something like this not only for your own sake
# But for getting rid huge amounts of code that can be compressed into stuff like this.
for item in ('Beenden', 'Datei', 'Bearbeiten', 'Dokumentationen', 'Hilfe'):
self.frames['_3_menubar'].Append(wxglade_tmp_menu, _(item))
With this you can simply do:
def getAllValues(self):
for frame in self.frames:
value = self.getValue(self.frames[frame])
yield (frame, value)
Or something similar, not sure what you want to do with the values but you could do:
def saveAllValues(self):
with open('settings.ini', 'w') as fh:
for frame, value in self.getAllValues():
fh.write(frame + ':' + str(value) + '\n')
I would suggest you do the following:
Use a dictionary to receive all the initial values. Let the names in the dictionary map to the names of your variables.
Allow other modules to subscribe to this GUI using the Observer Pattern.
When anything changes, or when the buttons are pressed, create a dictionary with the changes and notify all subscribers of the change.
This keeps the GUI cleanly separated from the rest of the program.
I'm trying to create a panel, with four boxes containing some data. These four boxes should have a predefined static size. What I have so far is four boxes that is overlapping to some extent.
Any ideas?
Code:
import wx
class MyFrame(wx.Frame):
def __init__(self, *args, **kwargs):
wx.Frame.__init__(self, *args, **kwargs)
self.pl = wx.Panel(self)
self.SetSize((500, 350))
sb = wx.StaticBox(self.pl, -1, 'BOX0', size=(180, 150))
sat = wx.CheckBox(self.pl, -1, 'Satellite')
gsm = wx.CheckBox(self.pl, -1, 'GSM')
wlan = wx.CheckBox(self.pl, -1, 'WLAN')
sb2 = wx.StaticBox(self.pl, -1, 'BOX1', size=(180, 150))
nm2 = wx.StaticText(self.pl, -1, 'default1')
sb3 = wx.StaticBox(self.pl, -1, 'BOX2', size=(180, 150))
nm3 = wx.StaticText(self.pl, -1, 'default2')
sb4 = wx.StaticBox(self.pl, -1, 'BOX3', size=(180, 150))
nm4 = wx.StaticText(self.pl, -1, 'default3')
box = wx.StaticBoxSizer(sb, wx.VERTICAL)
box.Add(sat, 0, wx.ALL, 5)
box.Add(gsm, 0, wx.ALL, 5)
box.Add(wlan, 0, wx.ALL, 5)
box2 = wx.StaticBoxSizer(sb2)
box2.Add(nm2, 0, wx.ALL, 5)
box3 = wx.StaticBoxSizer(sb3)
box3.Add(nm3, 0, wx.ALL, 5)
box4 = wx.StaticBoxSizer(sb4)
box4.Add(nm4, 0, wx.ALL, 5)
gs = wx.BoxSizer(wx.HORIZONTAL)
gs.Add(box)
gs.Add(box2)
gss = wx.BoxSizer(wx.HORIZONTAL)
gss.Add(box3)
gss.Add(box4)
gt = wx.BoxSizer(wx.VERTICAL)
gt.Add(gs)
gt.Add(gss)
self.pl.SetSizer(gt)
class MyApp(wx.App):
def OnInit(self):
frame = MyFrame(None, -1, '08_gridsizer.py')
frame.Show()
self.SetTopWindow(frame)
return 1
if __name__ == "__main__":
app = MyApp(0)
app.MainLoop()
I'll just answer my own question.
The solution is to add a wx.Sizer.SetMinSize() to each wx.StaticBoxSizer() like this.
sb = wx.StaticBox(self.pl, -1, 'BOX0')
sat = wx.CheckBox(self.pl, -1, 'Satellite')
gsm = wx.CheckBox(self.pl, -1, 'GSM')
wlan = wx.CheckBox(self.pl, -1, 'WLAN')
box = wx.StaticBoxSizer(sb, wx.VERTICAL)
box.SetMinSize((180, 150))
box.Add(sat, 0, wx.ALL, 5)
box.Add(gsm, 0, wx.ALL, 5)
box.Add(wlan, 0, wx.ALL, 5)
And I removed the size argument in wx.StaticText()