Level: Beginner
I am developing a GUI with wxPython on Windows 7 OS. Python version is 2.7 ad wxPython version is 3. My GUI looks as shown in the image below:
I would like to take some time to explain what I am trying to achieve. As you mayhave noticed from the first image that there are 4 different scrolled panels in my GUI named as panel-1 to panel-4. A vertical BoxSizer is applied to each scrolled panel. Each scrolled panel in return contains a boxsizer and a horizontal wx.StaticLine. The reason for using horizontal line was to make it is easier for the user to read the values for a particular serial number. (It will be easy for an user to read all the values in different panels for a particular serial number.) Finally all these four scrolled panels are added to a horizontal BoxSizer named as panelSizer. Currently the scrolled panels are scrolling individually. One important thing is that all the scrolled panels will every time contain same number of components/elements.
Problem:
I need a way so that I can add all these scrolled panels to one sizer or a panel in such a way that there is only one scroll bar at right side and when I scroll this scrollbar all the scrolled panels (panel-1 to panel-4) should scroll simultaneously. I would like to have something like this:
I think this option is better from the GUI perspective. I have tried couple of things like, I created a new scrolled panel named as main panel, and applied the BoxSizer named as panelSizer (it contains all the panel from panel-1 to panel-4) using SetSizer() function, but the scroll bar doesn't appears, even the individual scroll bars doesn't appear! Also, I have checked that there are enough components in the panels so that scroll bars appears. I tried to change the four scrolled panels to simple panels and then add to the panelSizer and then applied the sizer to the main panel but nothing solved the problem..
Can anyone suggest what is wrong with my approach? Any suggestion. Thank you for your time.
Well I found the solution myself so here it goes.
I have to disable scrolling on the panels-1 to panel-4. This can be done by not using SetupScrolling() method on them. Also, the scrolling should be enabled on the mainPanel like this:
mainPanel.SetupScrolling()
For an example: Consider that you have two scrolled panels named as panel1 and panel2. Now if you want to add these two scrolled panels to an other scrolled panel named as mainPanel, then you first create these two scrolled panels and then disable scrolling on them then add these two panels two a sizer, then apply this sizer to the mainPanel.
Code example:
mainPanel = wx.lib.scrolledpanel.ScrolledPanel(self, -1,style=wx.SIMPLE_BORDER)
mainPanel.SetupScrolling()
panel1 = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER)
panel2 = wx.lib.scrolledpanel.ScrolledPanel(mainPanel, -1, style=wx.SIMPLE_BORDER)
panelSizer = wx.BoxSizer(wx.HORIZONTAL)
panelSizer.Add(panel1)
panelSizer.Add(panel2)
mainPanel.SetSizer(panelSizer)
Related
Is it possible to group buttons that are arbitrarily positionned with PyQt ?
There is the context :
I would like to code a visual programm to control a research system with specific geometry, through Python.
I expect this kind of result :
In this program, the buttons of "buttons group 3" are positionned is a specific geometry that does not fit in a grid. Those buttons are clickable and a click on them change their color.
I would like those buttons to be grouped together, in something like a layout, because it seems to be that it is coherent in order to change positions and sizes of layouts and window if needed.
I'm coding that with PYQT5,... but I cannot figure in PyQt5 how to code this group of buttons with specific geometry ?
Is it possible to group buttons that are arbitrarily positionned with PyQt ?
Thanks in advance for your advice, I feel I'm missing something in PyQt concept.
I am Trying to figure out how to get a widget centered and fully shown in a layout.
The following code creates the widget and places it in the vertical layout just fine. However the widget is not centered in the layout and the bottom half is cut off.
widget = QtGui.QWidget()
FRM_widget = gsFRMPlaybackWidget.Ui_Form()
FRM_widget.setupUi(widget)
g_mainWindow.verticalLayout_mode.addWidget(widget,0)
The vertical layout is empty initially. I add a widget to it, then remove it later. The widget that is added is based on a combox selection. The contents and size of the widget will be different.
It will create the widget from another .py file (which is imported).
Is there some option for the vertical layout that I need to set? Is there an option for the widget I need to set?
Couldn't find anything that worked online.
I got to work.
In the gsFRMPlaybackWidget code (or designer) I had to set the forms layout to horizontally:expanding and vertically:preference for what I needed.
I want to remove the actual Close, minimize and maximize buttons of a window and create my own custom buttons, just like in chrome. I therefore want to add corner widgets to my tabwidget. Is there a way so that I can add three buttons as corner widgets of a QTabWidget?
Is it somehow possible to achieve using the QHBoxLayout ?
The setCornerWidget function just takes one widget as its input.
Add a generic QWidget as the corner widget.
Give it a QHBoxLayout.
Add your buttons to the layout.
I use this frequently, often by subclassing QTabWidget and creating accessor functions that return the individual buttons. Adding signals like buttonClicked(int) with the index and buttonClicked(QAbstractButton) with the button itself are helpful, too.
I was wondering if there is any way to control the location of the scrollbar from a scrolledpanel? More specifically: I use a horizontally scrolled panel and it would be nice if the scrollbar was on top of the panel (instead of bottom) and would only span 80% of the horizontal distance.
Is something like this possible?
Thanks...
What is the proper way to embedd grid (wx.grid.Grid) into the panel? I tried the following code and got bizarre frame:
wx.Frame.__init__(self,wx.GetApp().TopWindow,size=(600,800),title='Material Properties')
self.GridPanel=wx.Panel(self,-1)
grid=wx.grid.Grid(self.GridPanel,-1)
grid.CreateGrid(10,10)
I cannot see an easy way to create a grid which can also have buttons as well as menubar and other related widgets. Is there any example which shows GUI of how to implement wx.grid to achieve some sort of spreadsheet which has tabs on it for manipulation. I seem to be lost on this.
I want to create two different grid and also want to add some buttons and additional functionalites to the frame containing the table. Is there any better way to do that in wxpython?
I wrote about grids quite a while ago on my blog. You might find the following articles helpful for putting a Grid onto a Panel:
http://www.blog.pythonlibrary.org/2010/04/04/wxpython-grid-tips-and-tricks/
http://www.blog.pythonlibrary.org/2010/03/18/wxpython-an-introduction-to-grids/
Once you have that figured out, you can easily put the panel into a Notebook. If you want to add buttons, create the buttons and then add them to the sizer (see second example). Adding a Toolbar to the frame is covered in the wxPython demo, but I covered it here too:
http://www.blog.pythonlibrary.org/2008/07/02/wxpython-working-with-menus-toolbars-and-accelerators/