I want to make my window scrollable only if it goes less than a particular size (if it is opened on the laptop screen, it should be scrollable, but on a bigger monitor, it should not).
I believe this thing is done by using ScrolledWindow or ScrolledPanel by some way, but I exactly don’t know how. Below is a code snippet for the same
Even on the bigger monitor screen where defining self.notebook_1_pane_1 as a simple panel (using wx.Panel) gives proper GUI, making it a scrolledpanel is adding scrollbars even there and making all sizers take additional spaces.
Your panel is inside a notebook which is probably inside a frame.
Each of these has some window decoration. So the available space for the panel is less than the screen size. The panel size=(screenWidth,400) requires the scroll bars already.
P.P.S.: And please stop posting the same question on multiple lists/pages. I told you previously already. I will not answer any of your questions any more.
Hi, As you had said, I have not posted questions on multiple places after that.
This particular query went dead on StackOverflow, hence had to post it here too
So any solution for the problem?
I have tried changing the size = (a,b) parameters, but it still doesn’t work.
I have also updated the code to be a runnable one
Set the size on the top-level window, and let the Layout algorithm size everything within to the available space.
Here’s a runnable sample with scrollbars added only as needed:
import wx.lib
import wize as iz
app = wx.App()
screenSize = wx.DisplaySize()
screenWidth = screenSize[0]
screenHeight = screenSize[1]
with iz.Frame(size=(screenWidth,400), pos=(0,28), orient=wx.VERTICAL) as fr:
with iz.Notebook(flag=wx.EXPAND, proportion=1):
with iz.Page("page title"):
with iz.ScrolledWindow(style=wx.SIMPLE_BORDER, proportion=1, orient=wx.VERTICAL) as notebook_1_pane_1:
for _ in range(1,25):
iz.StaticText("Content that may or may not need scrolling")
fr.Layout()
fr.Show()
app.MainLoop()
Oh yes you did. You posted this question to both the mailing list and here. Not nice.
I saw the mailing list post first, and assumed you had gotten no answers, because there were no answers on the mailing list.
Yeah I was mentioning about this question only.
So Dietmar is talking about one earlier question that I had posted on 2 places a while back.
He told me (and rightly so) not to put same question on multiple places, and after that I am not doing that.(I’ve posted quite a few questions after that)
This particular question I posted here also because post on StackoverFlow went dead.
Regarding the mailing list thing, I think there is some issue with its updation. I posted the question and waited for 2 hours, and didn’t showed the question as posted.
So I posted the question here.
I got to know about Discuss wxPython from the mailing list only, it’s written in the Notice section…
If you don’t want scrollbars, then don’t create a ScrolledWindow or ScrolledPanel in the first place. Check the display size in advance and just use a regular wx.Panel on a big screen.
As I have mentioned in my question (and in the title also), I want a scrollbar when the window size is less than a particular size, like in a laptop screen.
So the GUI should not be scrollable when viewed on a bigger monitor, but it should be scrollable when viewed on a smaller screen like that of a laptop
@Tanmay_Agrawal As the other authors indicated, wx.lib.scrolledpanel.ScrolledPanel shows the scroll bars if it exceeds the client window size and hide them automatically if it doesn’t. Many controls manage their scroll bars like that.
Try this:
from wx.lib.scrolledpanel import ScrolledPanel
class MyFrame(wx.Frame):
def __init__(self, *args, **kwds):
wx.Frame.__init__(self, *args, **kwds)
self.panel = ScrolledPanel(self, size=(300,300))
self.panel.SetupScrolling()
In your code, I think you forgot wx.Notebook.AddPage.
EDIT Sorry that this code is not a good example. The argument size=(300,300) does not make sense.
Please see the following post. When you add widgets to the scrolledPanel sizer, it can manage the view of the children.
That’s the issue mate, it isn’t working… the sizers weirdly start taking additional spaces
Attaching the screenshot, when I use wx.lib.scrolledpanel.ScrolledPanel
Hi Tanmay,
Your application structure would be like this:
Frame/
Notebook/
ScrolledPanel/
<children>
When you add widgets to the scrolledPanel sizer, it can manage the view of the children.
For convenience and readability, create a scrollable custom panel:
I’ve re-read this thread and it looks like your problem is caused by the large panel you added to the scrolledpanel,
The width of the scrolledpanel client is always less than the screenWidth, so the scrollbar are always visible. How about reducing the panel size and seeing what happens?
Hi.
This inspection tool is really helpful
The issue is not solved, but now I know the exact problem.
Due to some reason, The SetVirtualSize parameter is not getting invoked. That’s why the windows is taking some VirtualSize on its own…
When from the inspection tool I set the Virtual Size and refresh it (via the Pycrust window), it works.
But I again have to give the command whenever I resize the window
So why is SetVirtualSize not getting invoked? How to invoke it everytime the window is resized?
Any solution for the problem?