Related
This is my code:
class TabTwo(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.resetButton = wx.Button(self, label="Reset")
self.contactButton = wx.Button(self, label="Contact")
self.copyrightButton = wx.Button(self, label="Copyright")
v_sizer = wx.BoxSizer(wx.VERTICAL)
h_sizer = wx.BoxSizer(wx.HORIZONTAL)
v_sizer.Add(self.resetButton, 0, wx.EXPAND, 30)
v_sizer.Add(self.contactButton, 0, wx.EXPAND, 30)
v_sizer.Add(self.copyrightButton, 0, wx.EXPAND, 30)
self.SetSizer(v_sizer)
How do I add some space between the buttons (Reset, Contact and Copyright) so that it doesn't look to much like it's been pressed together.
Specify a border when adding to the sizer:
v_sizer.Add( self.resetButton, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 )
v_sizer.Add( self.contactButton, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 )
v_sizer.Add( self.copyrightButton, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 5 )
Here wx.TOP|wx.BOTTOM specifies to add a border to the top and bottom of the widget. I'm assuming you just want top and bottom; wx.ALL adds on all sides. Also wx.RIGHT and wx.LEFT are available.
The parameter following wx.EXPAND|wx.TOP|wx.BOTTOM (ie 5) is the size of the border.
See here for more information: https://wxpython.org/Phoenix/docs/html/wx.Sizer.html#wx-sizer. In particular the Add function and the flag and border parameters.
I made a small and simple program using wx.BoxSizer.
Here is the source code:'
import wx
# MAIN PROGRAM...
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "My Frame", size = (600, 600))
mainPanel = wx.Panel(self)
mainBox = wx.BoxSizer(wx.VERTICAL)
header1 = wx.StaticText(mainPanel, label = 'Header1:')
header2 = wx.StaticText(mainPanel, label = 'Header2:')
panel1 = wx.Panel(mainPanel, size = (200, 200), style = wx.SUNKEN_BORDER)
panel2 = wx.Panel(mainPanel, size = (200, 200), style = wx.SUNKEN_BORDER)
box1 = wx.BoxSizer(wx.HORIZONTAL)
box1.AddSpacer(50)
box1.Add(header1, 0, wx.ALL, 5)
box1.AddSpacer(50)
box1.Add(header2, 0, wx.ALL, 5)
box2 = wx.BoxSizer(wx.HORIZONTAL)
box2.Add(panel1, 0, wx.ALL, 5)
box2.Add(panel2, 0, wx.ALL, 5)
mainBox.Add(box1, 0, wx.ALL, 5)
mainBox.Add(box2, 0, wx.ALL, 5)
mainPanel.SetSizer(mainBox)
#self.Center()
if __name__ == '__main__':
app = wx.App()
frame = MyFrame()
frame.Show(True)
app.MainLoop()
print 'Exiting...'
The issue is that when, I add horizontal space to the left of each header, it also adds vertical space between the headers and sunken_border header1 and header2. Is there anyway to just add the horizontal space before the headers without adding the vertical space as a side effect?
Thanks.
---EDIT---
To answer your comment:
here is a picture of the program:
Simple BoxSizer program...
The 'space' in green is wanted space, but the 'space' in red is an unneeded side effect. I basically only want the green space, but I don't want the red space, I want the headers to be flush with the two panels (like right directly on top...).
Right now, I am having to do absolute positioning to get it to work, I just wanted to know if you can make it work with BoxSizer or some other layout manager...
Thanks again.
When you write
Add( ..., 0, wx.ALL, 5)
you are adding 5 pixels ALL AROUND.
So:
box1.Add(header1, 0, wx.ALL, 5)
adds 5 pizels below header 1
box2.Add(panel1, 0, wx.ALL, 5)
adds 5 pixels above panel 1
mainBox.Add(box1, 0, wx.ALL, 5)
adds 5 pixels below header 1 ( contained in box1 )
mainBox.Add(box2, 0, wx.ALL, 5)
adds 5 pixels above panel1 ( contained in box2 )
for a total of 20 extra pixels.
If you do not want white space in the vertical direction, do not write
Add( ..., 0, wx.ALL, 5)
Instead, something like this
mainPanel = wx.Panel(self)
mainBox = wx.BoxSizer(wx.VERTICAL)
header1 = wx.StaticText(mainPanel, label = 'Header1:')
header2 = wx.StaticText(mainPanel, label = 'Header2:')
panel1 = wx.Panel(mainPanel, size = (200, 200), style = wx.SUNKEN_BORDER)
panel2 = wx.Panel(mainPanel, size = (200, 200), style = wx.SUNKEN_BORDER)
box1 = wx.BoxSizer(wx.HORIZONTAL)
box1.AddSpacer(50)
box1.Add(header1)
box1.AddSpacer(50)
box1.Add(header2)
box2 = wx.BoxSizer(wx.HORIZONTAL)
box2.AddSpacer(5)
box2.Add(panel1)
box2.AddSpacer(10)
box2.Add(panel2)
mainBox.AddSpacer(5)
mainBox.Add(box1)
mainBox.Add(box2)
mainPanel.SetSizer(mainBox)
#self.Center()
I found the solution!
instead of this:
box1.AddSpacer(50)
do this...
box1.AddSpacer((50, 0))
It works, yay!
Thanks.
I'm trying to hone my Python skills by creating a simple app to organize an itinerary. The basis of the app is that you enter the task to add, then another window pops out to ask for the due date and priority of the task. The second window has a submit button that is supposed to add all the gathered information to a list box with multiple columns.
My issue is where to create an array to hold the information so that it can be added. I can't add it to the add function itself, because it needs to be referenced by other functions.
I've tried adding it to the __init__ of my MainWindow, but that's where I get stuck. I don't know how to reference the array once it's there. Simply referencing the name (toAdd) give me exception
Traceback (most recent call last):
File "Making GUI - First Shot (Development).py", line 60, in AddItem
toAdd.append(appendItem)
NameError: global name 'toAdd' is not defined
Here's my code:
import wx
class mainWindow(wx.Frame):
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, title=title, size=(650, 500))
panel = wx.Panel(self)
vbox = wx.BoxSizer(wx.VERTICAL)
hbox1 = wx.BoxSizer(wx.HORIZONTAL)
hbox2 = wx.BoxSizer(wx.HORIZONTAL)
menubar = wx.MenuBar()
topFont = wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL)
self.topLabel = wx.StaticText(panel, size = (-1, -1), label="Itinerary")
font = wx.Font(10, wx.SWISS, wx.NORMAL, wx.NORMAL)
self.topLabel.SetFont(topFont)
vbox.Add(self.topLabel, 0, wx.ALL, 2)
vbox.Add((-1, 10))
self.listBox = wx.ListCtrl(panel, style = wx.LC_REPORT)
self.listBox.InsertColumn(0, "Priority", width = 150)
self.listBox.InsertColumn(0, "Due Date (if applicable)", width = 250)
self.listBox.InsertColumn(0, "Task", width=250)
self.listBox.SetFont(font)
vbox.Add(self.listBox, 1, wx.EXPAND | wx.ALL, 2)
hbox1.Add((5, -1))
self.newItemInput = wx.TextCtrl(panel, size = (400, -1))
hbox2.Add(self.newItemInput, 1, wx.ALIGN_LEFT | wx.ALL, 1)
self.submitButton = wx.Button(panel, size = (100, -1))
self.submitButton.SetLabel("Hello")
self.Bind(wx.EVT_BUTTON, self.AddItem, self.submitButton)
hbox2.Add(self.submitButton, 1, wx.ALIGN_RIGHT | wx.ALL, 2)
vbox.Add(hbox1, 0, wx.ALL, 2)
vbox.Add(hbox2, 0, wx.EXPAND | wx.ALL, 2)
vbox.Add((-1, 35))
panel.SetSizer(vbox)
self.Show(True)
toAdd = []
def AddItem(self, event):
appendItem = self.newItemInput.GetValue()
toAdd.append(appendItem)
confirmBox = wx.Frame(frame, title = "Task Details", size = (300, 150))
confirmVert = wx.BoxSizer(wx.VERTICAL)
confirmHoriz1 = wx.BoxSizer(wx.HORIZONTAL)
confirmHoriz2 = wx.BoxSizer(wx.HORIZONTAL)
confirmHoriz3 = wx.BoxSizer(wx.HORIZONTAL)
confirmHoriz4 = wx.BoxSizer(wx.HORIZONTAL)
confirmPrompt = wx.StaticText(confirmBox, size = (25, -1), label = "Due Date for " + toAdd[0])
confirmHoriz1.Add(confirmPrompt, 1, wx.EXPAND | wx.ALIGN_CENTER)
addingDate = wx.TextCtrl(confirmBox, size = (25, -1))
confirmHoriz2.Add(addingDate, 1, wx.EXPAND | wx.ALIGN_CENTER)
confirmPriority = wx.StaticText(confirmBox, size = (25, -1), label = "Priority")
confirmHoriz3.Add(confirmPriority, 1, wx.EXPAND | wx.ALIGN_CENTER)
addingPriority = wx.TextCtrl(confirmBox, size = (25, -1))
confirmHoriz4.Add(addingPriority, 1, wx.EXPAND | wx.ALIGN_CENTER)
addListButton = wx.Button(confirmBox, size = (-1, 25), label = "Submit")
confirmVert.Add(confirmHoriz1, 0, wx.EXPAND | wx.ALIGN_CENTER)
confirmVert.Add(confirmHoriz2, 0, wx.EXPAND | wx.ALIGN_CENTER)
confirmVert.Add(confirmHoriz3, 0, wx.EXPAND | wx.ALIGN_CENTER)
confirmVert.Add(confirmHoriz4, 0, wx.EXPAND | wx.ALIGN_CENTER)
confirmVert.Add(addListButton, 0, wx.EXPAND | wx.ALIGN_CENTER)
def itemSubmit(self):
date = addingDate.GetValue()
priority = addingPriority.GetValue()
toAdd.append(date)
toAdd.append(priority)
panel.listBox.Append(toAdd)
confirmBox.Bind(wx.EVT_BUTTON, itemSubmit, addListButton)
confirmBox.SetSizer(confirmVert)
confirmBox.Show()
app = wx.App(False)
frame = mainWindow(None, "Itinerary Manager")
app.MainLoop()
How would I go about making AddItem append the information to toAdd so that I can then append toAdd to the ListCtrl on the main window?
Utilise the self reference for your data items, so declare
toAdd = []
as
self.toAdd[]
this should apply to your other variables as well.
The first argument of every class method, including init, is always a reference to the current instance of the class. By convention, this argument is always named self. It isn't a rule just a convention.
I'm using wxpython to code this simple form. A notebook with a scroll bar and few text controls is what i have used.I can see the widgets which are view-able on screen but the ones which needs to be scrolled down are not visible. In my code below i could see upto "Enter the Logs" and appropriate text control for that fields but the "review fields are missing along with submit and cancel buttons.
import wx
import wx.lib.filebrowsebutton as filebrowse
class Frame ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Test", pos = wx.DefaultPosition, size = wx.Size( 600,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
sizer = wx.BoxSizer( wx.VERTICAL )
self.notebook = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
self.login = wx.Panel( self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
self.notebook.AddPage( self.login, u"Login", False )
self.scroll = wx.ScrolledWindow( self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL )
vbox = wx.BoxSizer(wx.VERTICAL)
# Sizer for widgets inside tabs
inside_sizer_h1 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h2 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h3 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h4 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h5 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h6 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h7 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h8 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h9 = wx.BoxSizer(wx.HORIZONTAL)
#Test Approve Label
self.test_app_label = wx.StaticText(self.scroll, -1 , label="Test Approved By :")
inside_sizer_h1.Add(self.test_app_label, 1, wx.ALL,5)
#Test Approve Combo
self.tes_app_combo = wx.ComboBox(self.scroll, -1, value='None', choices= ['None', 'approver1', 'approver2', 'approver3', 'approver4'] )
inside_sizer_h1.Add(self.tes_app_combo, 1, wx.ALL, 5 )
#Workspace Label
self.wrksp_label = wx.StaticText(self.scroll, -1 , label="Workspace :")
inside_sizer_h2.Add(self.wrksp_label, 1, wx.ALL,5)
#Workspace file selector
self.select_wrksp_dir = filebrowse.DirBrowseButton(self.scroll, -1,labelText = "", toolTip = 'Select tip of your workspace')
inside_sizer_h2.Add(self.select_wrksp_dir, 1, wx.ALL|wx.EXPAND, 5 )
# Issuelist label
self.ar_list_label = wx.StaticText(self.scroll, -1 , label="Issue List :")
inside_sizer_h3.Add(self.ar_list_label, 1, wx.ALL,5)
# Issue Text box
self.ar_list_text = wx.TextCtrl(self.scroll, -1, value=u"Enter The issue, one per line", style=wx.TE_MULTILINE)
inside_sizer_h3.Add(self.ar_list_text, 1, wx.ALL, 5 )
# Summary of change Title
self.change_summary_label = wx.StaticText(self.scroll, -1 , label=u"Summary of change :")
inside_sizer_h4.Add(self.change_summary_label, 1, wx.ALL, 5)
# Summary of change Text Box
self.change_summary_text = wx.TextCtrl(self.scroll, -1, value=u"What componet has changed?",style=wx.TE_MULTILINE)
inside_sizer_h4.Add(self.change_summary_text, 1, wx.ALL, 5 )
# Changed File List Title
self.change_file_list_label = wx.StaticText(self.scroll, -1 , label=u"Changed File List :")
inside_sizer_h5.Add(self.change_file_list_label,1, wx.ALL, 5)
# Changed File List Box
self.change_summary_text = wx.TextCtrl(self.scroll, -1, u' enter list of changed files',style=wx.TE_MULTILINE)
inside_sizer_h5.Add(self.change_summary_text,1, wx.ALL, 5)
# GUI Testing done label
self.testing_done_label = wx.StaticText(self.scroll, -1 , label=u"What tests have you done? :")
inside_sizer_h6.Add(self.testing_done_label,1, wx.ALL, 5)
#FlexGUi Checkbox
self.gui_check_list = wx.CheckListBox(self.scroll, -1, choices=['GUI Builds Successfully', 'GUI Automation Tests', 'CLI Automation Tests'])
inside_sizer_h6.Add(self.gui_check_list,1, wx.ALL, 5)
# GUI Automation test logs label
self.gui_auto_log_label = wx.StaticText(self.scroll, -1 , label=u"Enter the logs :")
inside_sizer_h7.Add(self.gui_auto_log_label,1, wx.ALL, 5)
#GUI Automation test box
self.gui_auto_log = wx.TextCtrl(self.scroll, -1, u'Copy and paste the logs.',style=wx.TE_MULTILINE)
inside_sizer_h7.Add(self.gui_auto_log,1, wx.ALL, 5)
# Review URL Text
self.review_url_label = wx.StaticText(self.scroll, -1 , label=u"Code review URL :")
inside_sizer_h8.Add(self.review_url_label,1, wx.ALL, 5)
#Code Review Textbox
self.review_url_tbox = wx.TextCtrl(self.scroll, -1, value=u"Enter the code review URL",style=wx.TE_MULTILINE)
inside_sizer_h8.Add(self.review_url_tbox,1, wx.ALL, 5)
#Submit button
self.sub_button = wx.Button(self.scroll, label = 'Submit')
inside_sizer_h9.Add(self.sub_button, wx.ALL, 5)
#Cancel button
self.canc_button = wx.Button(self.scroll, label = 'Cancel')
inside_sizer_h9.Add(self.canc_button,1, wx.ALL, 5)
vbox.Add(inside_sizer_h1, 0 , wx.TOP|wx.EXPAND, 40 )
vbox.Add(inside_sizer_h2, 0 , wx.ALL|wx.EXPAND, 5 )
vbox.Add(inside_sizer_h3, 0 , wx.ALL|wx.EXPAND, 5 )
vbox.Add(inside_sizer_h4, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h5, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h6, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h7, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h8, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h9, 0 , wx.ALL|wx.EXPAND, 10)
self.Maximize()
self.scroll.Size = self.GetSize()
print self.GetSize()
self.scroll.SetScrollbars(20,25,45,50)
self.SetSizer( vbox )
self.SetSizerAndFit(vbox)
self.Layout()
self.notebook.AddPage( self.scroll, u"Delivery", True )
sizer.Add( self.notebook, 1, wx.EXPAND |wx.ALIGN_RIGHT|wx.ALL, 0 )
self.SetSizer( sizer )
self.Layout()
self.Centre( wx.BOTH )
self.Show()
if name == "main":
app = wx.App()
Frame(None)
app.MainLoop()
Your code (amended) working on Linux:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import wx.lib.filebrowsebutton as filebrowse
class Frame ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Test", pos = wx.DefaultPosition, size = wx.Size( 600,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
sizer = wx.BoxSizer( wx.VERTICAL )
self.notebook = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
self.login = wx.Panel( self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
self.notebook.AddPage( self.login, u"Login", False )
self.scroll = wx.ScrolledWindow( self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL )
vbox = wx.BoxSizer(wx.VERTICAL)
# Sizer for widgets inside tabs
inside_sizer_h1 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h2 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h3 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h4 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h5 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h6 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h7 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h8 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h9 = wx.BoxSizer(wx.HORIZONTAL)
#Test Approve Label
self.test_app_label = wx.StaticText(self.scroll, -1 , label="Test Approved By :")
inside_sizer_h1.Add(self.test_app_label, 1, wx.ALL,5)
#Test Approve Combo
self.tes_app_combo = wx.ComboBox(self.scroll, -1, value='None', choices= ['None', 'approver1', 'approver2', 'approver3', 'approver4'] )
inside_sizer_h1.Add(self.tes_app_combo, 1, wx.ALL, 5 )
#Workspace Label
self.wrksp_label = wx.StaticText(self.scroll, -1 , label="Workspace :")
inside_sizer_h2.Add(self.wrksp_label, 1, wx.ALL,5)
#Workspace file selector
self.select_wrksp_dir = filebrowse.DirBrowseButton(self.scroll, -1,labelText = "", toolTip = 'Select tip of your workspace')
inside_sizer_h2.Add(self.select_wrksp_dir, 1, wx.ALL|wx.EXPAND, 5 )
# Issuelist label
self.ar_list_label = wx.StaticText(self.scroll, -1 , label="Issue List :")
inside_sizer_h3.Add(self.ar_list_label, 1, wx.ALL,5)
# Issue Text box
self.ar_list_text = wx.TextCtrl(self.scroll, -1, value=u"Enter The issue, one per line", style=wx.TE_MULTILINE)
inside_sizer_h3.Add(self.ar_list_text, 1, wx.ALL, 5 )
# Summary of change Title
self.change_summary_label = wx.StaticText(self.scroll, -1 , label=u"Summary of change :")
inside_sizer_h4.Add(self.change_summary_label, 1, wx.ALL, 5)
# Summary of change Text Box
self.change_summary_text = wx.TextCtrl(self.scroll, -1, value=u"What componet has changed?",style=wx.TE_MULTILINE)
inside_sizer_h4.Add(self.change_summary_text, 1, wx.ALL, 5 )
# Changed File List Title
self.change_file_list_label = wx.StaticText(self.scroll, -1 , label=u"Changed File List :")
inside_sizer_h5.Add(self.change_file_list_label,1, wx.ALL, 5)
# Changed File List Box
self.change_summary_text = wx.TextCtrl(self.scroll, -1, u' enter list of changed files',style=wx.TE_MULTILINE)
inside_sizer_h5.Add(self.change_summary_text,1, wx.ALL, 5)
# GUI Testing done label
self.testing_done_label = wx.StaticText(self.scroll, -1 , label=u"What tests have you done? :")
inside_sizer_h6.Add(self.testing_done_label,1, wx.ALL, 5)
#FlexGUi Checkbox
self.gui_check_list = wx.CheckListBox(self.scroll, -1, choices=['GUI Builds Successfully', 'GUI Automation Tests', 'CLI Automation Tests'])
inside_sizer_h6.Add(self.gui_check_list,1, wx.ALL, 5)
# GUI Automation test logs label
self.gui_auto_log_label = wx.StaticText(self.scroll, -1 , label=u"Enter the logs :")
inside_sizer_h7.Add(self.gui_auto_log_label,1, wx.ALL, 5)
#GUI Automation test box
self.gui_auto_log = wx.TextCtrl(self.scroll, -1, u'Copy and paste the logs.',style=wx.TE_MULTILINE)
inside_sizer_h7.Add(self.gui_auto_log,1, wx.ALL, 5)
# Review URL Text
self.review_url_label = wx.StaticText(self.scroll, -1 , label=u"Code review URL :")
inside_sizer_h8.Add(self.review_url_label,1, wx.ALL, 5)
#Code Review Textbox
self.review_url_tbox = wx.TextCtrl(self.scroll, -1, value=u"Enter the code review URL",style=wx.TE_MULTILINE)
inside_sizer_h8.Add(self.review_url_tbox,1, wx.ALL, 5)
#Submit button
self.sub_button = wx.Button(self.scroll, label = 'Submit')
inside_sizer_h9.Add(self.sub_button,1, wx.ALL, 5)
#Cancel button
self.canc_button = wx.Button(self.scroll, label = 'Cancel')
inside_sizer_h9.Add(self.canc_button,1, wx.ALL, 5)
vbox.Add(inside_sizer_h1, 0 , wx.TOP|wx.EXPAND, 40 )
vbox.Add(inside_sizer_h2, 0 , wx.ALL|wx.EXPAND, 5 )
vbox.Add(inside_sizer_h3, 0 , wx.ALL|wx.EXPAND, 5 )
vbox.Add(inside_sizer_h4, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h5, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h6, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h7, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h8, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h9, 0 , wx.ALL|wx.EXPAND, 10)
self.Maximize()
self.scroll.Size = self.GetSize()
print self.GetSize()
self.scroll.SetScrollbars(20,25,45,50)
self.SetSizer( vbox )
self.SetSizerAndFit(vbox)
self.Layout()
self.notebook.AddPage( self.scroll, u"Delivery", True )
sizer.Add( self.notebook, 1, wx.EXPAND |wx.ALIGN_RIGHT|wx.ALL, 0 )
self.SetSizer( sizer )
self.Layout()
self.Centre( wx.BOTH )
self.Show()
if __name__ == "__main__":
app = wx.App()
Frame(None)
app.MainLoop()
When adding your items to the sizer, you consistently set the proportion value to 1, with the exception of self.sub_button. It is that which is causing your problem.
inside_sizer_h9.Add(self.sub_button, wx.ALL, 5)
should read:
inside_sizer_h9.Add(self.sub_button,1, wx.ALL, 5)
Note also that the posted code main is incorrect and should read:
if __name__ == "__main__":
With those amendments you code should work as you wrote it.
The following code compiles and runs good on both windows and linux platforms, but the fields which needs to be scrolled for viewing(V_scroll) are missing from windows but no such problems with linux. wx 3.0 is installed in windows and 2.8.1 in linux. Would that be a problem?
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
import wx.lib.filebrowsebutton as filebrowse
class Frame ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Test", pos = wx.DefaultPosition, size = wx.Size( 600,300 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHintsSz( wx.DefaultSize, wx.DefaultSize )
sizer = wx.BoxSizer( wx.VERTICAL )
self.notebook = wx.Notebook( self, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, 0 )
self.login = wx.Panel( self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
self.notebook.AddPage( self.login, u"Login", False )
self.scroll = wx.ScrolledWindow( self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.HSCROLL|wx.VSCROLL )
vbox = wx.BoxSizer(wx.VERTICAL)
# Sizer for widgets inside tabs
inside_sizer_h1 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h2 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h3 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h4 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h5 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h6 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h7 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h8 = wx.BoxSizer(wx.HORIZONTAL)
inside_sizer_h9 = wx.BoxSizer(wx.HORIZONTAL)
#Test Approve Label
self.test_app_label = wx.StaticText(self.scroll, -1 , label="Test Approved By :")
inside_sizer_h1.Add(self.test_app_label, 1, wx.ALL,5)
#Test Approve Combo
self.tes_app_combo = wx.ComboBox(self.scroll, -1, value='None', choices= ['None', 'approver1', 'approver2', 'approver3', 'approver4'] )
inside_sizer_h1.Add(self.tes_app_combo, 1, wx.ALL, 5 )
#Workspace Label
self.wrksp_label = wx.StaticText(self.scroll, -1 , label="Workspace :")
inside_sizer_h2.Add(self.wrksp_label, 1, wx.ALL,5)
#Workspace file selector
self.select_wrksp_dir = filebrowse.DirBrowseButton(self.scroll, -1,labelText = "", toolTip = 'Select tip of your workspace')
inside_sizer_h2.Add(self.select_wrksp_dir, 1, wx.ALL|wx.EXPAND, 5 )
# Issuelist label
self.ar_list_label = wx.StaticText(self.scroll, -1 , label="Issue List :")
inside_sizer_h3.Add(self.ar_list_label, 1, wx.ALL,5)
# Issue Text box
self.ar_list_text = wx.TextCtrl(self.scroll, -1, value=u"Enter The issue, one per line", style=wx.TE_MULTILINE)
inside_sizer_h3.Add(self.ar_list_text, 1, wx.ALL, 5 )
# Summary of change Title
self.change_summary_label = wx.StaticText(self.scroll, -1 , label=u"Summary of change :")
inside_sizer_h4.Add(self.change_summary_label, 1, wx.ALL, 5)
# Summary of change Text Box
self.change_summary_text = wx.TextCtrl(self.scroll, -1, value=u"What componet has changed?",style=wx.TE_MULTILINE)
inside_sizer_h4.Add(self.change_summary_text, 1, wx.ALL, 5 )
# Changed File List Title
self.change_file_list_label = wx.StaticText(self.scroll, -1 , label=u"Changed File List :")
inside_sizer_h5.Add(self.change_file_list_label,1, wx.ALL, 5)
# Changed File List Box
self.change_summary_text = wx.TextCtrl(self.scroll, -1, u' enter list of changed files',style=wx.TE_MULTILINE)
inside_sizer_h5.Add(self.change_summary_text,1, wx.ALL, 5)
# GUI Testing done label
self.testing_done_label = wx.StaticText(self.scroll, -1 , label=u"What tests have you done? :")
inside_sizer_h6.Add(self.testing_done_label,1, wx.ALL, 5)
#FlexGUi Checkbox
self.gui_check_list = wx.CheckListBox(self.scroll, -1, choices=['GUI Builds Successfully', 'GUI Automation Tests', 'CLI Automation Tests'])
inside_sizer_h6.Add(self.gui_check_list,1, wx.ALL, 5)
# GUI Automation test logs label
self.gui_auto_log_label = wx.StaticText(self.scroll, -1 , label=u"Enter the logs :")
inside_sizer_h7.Add(self.gui_auto_log_label,1, wx.ALL, 5)
#GUI Automation test box
self.gui_auto_log = wx.TextCtrl(self.scroll, -1, u'Copy and paste the logs.',style=wx.TE_MULTILINE)
inside_sizer_h7.Add(self.gui_auto_log,1, wx.ALL, 5)
# Review URL Text
self.review_url_label = wx.StaticText(self.scroll, -1 , label=u"Code review URL :")
inside_sizer_h8.Add(self.review_url_label,1, wx.ALL, 5)
#Code Review Textbox
self.review_url_tbox = wx.TextCtrl(self.scroll, -1, value=u"Enter the code review URL",style=wx.TE_MULTILINE)
inside_sizer_h8.Add(self.review_url_tbox,1, wx.ALL, 5)
#Submit button
self.sub_button = wx.Button(self.scroll, label = 'Submit')
inside_sizer_h9.Add(self.sub_button,1, wx.ALL, 5)
#Cancel button
self.canc_button = wx.Button(self.scroll, label = 'Cancel')
inside_sizer_h9.Add(self.canc_button,1, wx.ALL, 5)
vbox.Add(inside_sizer_h1, 0 , wx.TOP|wx.EXPAND, 40 )
vbox.Add(inside_sizer_h2, 0 , wx.ALL|wx.EXPAND, 5 )
vbox.Add(inside_sizer_h3, 0 , wx.ALL|wx.EXPAND, 5 )
vbox.Add(inside_sizer_h4, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h5, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h6, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h7, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h8, 0 , wx.ALL|wx.EXPAND, 10)
vbox.Add(inside_sizer_h9, 0 , wx.ALL|wx.EXPAND, 10)
self.Maximize()
self.scroll.Size = self.GetSize()
print self.GetSize()
self.scroll.SetScrollbars(20,25,45,50)
self.SetSizer( vbox )
self.SetSizerAndFit(vbox)
self.Layout()
self.notebook.AddPage( self.scroll, u"Delivery", True )
sizer.Add( self.notebook, 1, wx.EXPAND |wx.ALIGN_RIGHT|wx.ALL, 0 )
self.SetSizer( sizer )
self.Layout()
self.Centre( wx.BOTH )
self.Show()
if __name__ == "__main__":
app = wx.App()
Frame(None)
app.MainLoop()
I don't see why you use so many sizers, here I use a FlexGridSizer instead. But your problem is really due to you using self.SetSizer(vbox) and then later self.SetSizer(sizer), the first one should be self.scroll.SetSizer(vbox).
There is one issue I haven't figured out with the following, that is the TextCtrl where I defined wx.EXPAND are not expanding.
#!/usr/bin/python
# -*- coding: utf-8 -*-
import wx
print(wx.VERSION_STRING)
import wx.lib.filebrowsebutton as filebrowse
class Frame ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"Test", pos = wx.DefaultPosition, style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
sizer = wx.BoxSizer( wx.VERTICAL )
self.notebook = wx.Notebook( self, wx.ID_ANY)
self.login = wx.Panel( self.notebook, wx.ID_ANY)
self.notebook.AddPage( self.login, u"Login", False )
self.scroll = wx.lib.scrolledpanel.ScrolledPanel( self.notebook, wx.ID_ANY)
vbox = wx.BoxSizer(wx.VERTICAL)
# Sizer for widgets inside tabs
inside_sizer = wx.FlexGridSizer(cols=2)
button_sizer = wx.BoxSizer()
#Test Approve Label
self.test_app_label = wx.StaticText(self.scroll, -1 , label="Test Approved By :")
inside_sizer.Add(self.test_app_label, 1, wx.ALL,5)
#Test Approve Combo
self.tes_app_combo = wx.ComboBox(self.scroll, -1, value='None', choices= ['None', 'approver1', 'approver2', 'approver3', 'approver4'] )
inside_sizer.Add(self.tes_app_combo, 1, wx.ALL, 5 )
#Workspace Label
self.wrksp_label = wx.StaticText(self.scroll, -1 , label="Workspace :")
inside_sizer.Add(self.wrksp_label, 1, wx.ALL,5)
#Workspace file selector
self.select_wrksp_dir = filebrowse.DirBrowseButton(self.scroll, -1,labelText = "", toolTip = 'Select tip of your workspace')
inside_sizer.Add(self.select_wrksp_dir, 1, wx.ALL|wx.EXPAND, 5 )
# Issuelist label
self.ar_list_label = wx.StaticText(self.scroll, -1 , label="Issue List :")
inside_sizer.Add(self.ar_list_label, 1, wx.ALL,5)
# Issue Text box
self.ar_list_text = wx.TextCtrl(self.scroll, -1, value=u"Enter The issue, one per line", style=wx.TE_MULTILINE)
inside_sizer.Add(self.ar_list_text, 1, wx.ALL|wx.EXPAND, 5 )
# Summary of change Title
self.change_summary_label = wx.StaticText(self.scroll, -1 , label=u"Summary of change :")
inside_sizer.Add(self.change_summary_label, 1, wx.ALL, 5)
# Summary of change Text Box
self.change_summary_text = wx.TextCtrl(self.scroll, -1, value=u"What componet has changed?",style=wx.TE_MULTILINE)
inside_sizer.Add(self.change_summary_text, 1, wx.ALL|wx.EXPAND, 5 )
# Changed File List Title
self.change_file_list_label = wx.StaticText(self.scroll, -1 , label=u"Changed File List :")
inside_sizer.Add(self.change_file_list_label,1, wx.ALL, 5)
# Changed File List Box
self.change_summary_text = wx.TextCtrl(self.scroll, -1, u' enter list of changed files',style=wx.TE_MULTILINE)
inside_sizer.Add(self.change_summary_text,1, wx.ALL|wx.EXPAND, 5)
# GUI Testing done label
self.testing_done_label = wx.StaticText(self.scroll, -1 , label=u"What tests have you done? :")
inside_sizer.Add(self.testing_done_label,1, wx.ALL, 5)
#FlexGUi Checkbox
self.gui_check_list = wx.CheckListBox(self.scroll, -1, choices=['GUI Builds Successfully', 'GUI Automation Tests', 'CLI Automation Tests'])
inside_sizer.Add(self.gui_check_list,1, wx.ALL, 5)
# GUI Automation test logs label
self.gui_auto_log_label = wx.StaticText(self.scroll, -1 , label=u"Enter the logs :")
inside_sizer.Add(self.gui_auto_log_label,1, wx.ALL, 5)
#GUI Automation test box
self.gui_auto_log = wx.TextCtrl(self.scroll, -1, u'Copy and paste the logs.',style=wx.TE_MULTILINE)
inside_sizer.Add(self.gui_auto_log,1, wx.ALL|wx.EXPAND, 5)
# Review URL Text
self.review_url_label = wx.StaticText(self.scroll, -1 , label=u"Code review URL :")
inside_sizer.Add(self.review_url_label,1, wx.ALL, 5)
#Code Review Textbox
self.review_url_tbox = wx.TextCtrl(self.scroll, -1, value=u"Enter the code review URL",style=wx.TE_MULTILINE)
inside_sizer.Add(self.review_url_tbox,1, wx.ALL|wx.EXPAND, 5)
#Submit button
self.sub_button = wx.Button(self.scroll, label = 'Submit')
button_sizer.Add(self.sub_button,1, wx.ALL, 5)
#Cancel button
self.canc_button = wx.Button(self.scroll, label = 'Cancel')
button_sizer.Add(self.canc_button,1, wx.ALL, 5)
vbox.Add(inside_sizer, 1, wx.TOP|wx.EXPAND, 40 )
vbox.Add(button_sizer, 1, wx.TOP, 40 )
self.scroll.SetupScrolling()
self.scroll.SetSizer(vbox)
self.notebook.AddPage( self.scroll, u"Delivery", True )
sizer.Add( self.notebook, 1, wx.EXPAND|wx.ALIGN_RIGHT|wx.ALL, 0 )
self.SetSizer( sizer )
self.Layout()
self.Centre( wx.BOTH )
self.Show()
self.Maximize()
if __name__ == "__main__":
import wx.lib.mixins.inspection as WIT
app = WIT.InspectableApp()
Frame(None)
app.MainLoop()