Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6017635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T03:09:27+00:00 2026-05-23T03:09:27+00:00

So I have a wx.Frame to which I add a GLCanvas and some buttons.

  • 0

So I have a wx.Frame to which I add a GLCanvas and some buttons. Here is the part that ads these:

self.sizer = wx.FlexGridSizer(2,2,20,20)
        self.xSize = FRAME_WIDTH - MIN_BUT_SIZE
        self.ySize = FRAME_HEIGHT - 40
        self.canvas = myGLCanvas(self, size=(self.xSize, self.ySize))
        self.panel = GLPanel(self, canvas=self.canvas)
        self.sizer.Add(self.canvas, 1, wx.EXPAND)
        self.sizer.Add(self.panel, 0, wx.EXPAND)
        self.headerSizer.DeleteWindows()
        self.centerSizer.Remove(self.headerSizer)
        self.Layout()
        self.centerSizer.Add(self.sizer)
        self.goBack = wx.Button(self, -1, str("Go Back!"))
        self.sizer.Add(self.goBack, 0, wx.ALIGN_CENTER_HORIZONTAL, 2)
        self.sizer.Add((20,20))
        self.SetSizerAndFit(self.mainGrid)
        self.Bind(wx.EVT_SIZING, self.OnSizing) 

I have to mention here that self.centerSizer is already added to self.mainGrid at this point along with another sizer that I user for some buttons. Now if I use self.SetSizer(mainGrid) instead of SetSizerAndFit(), the components I added in the above code are not positioned properly UNTIL I resize my frame manually. With SetSizerAndFit this works. But now I want my gl canvas to resize with my frame. So my approach is:

def OnSizing(self, event):
    size = self.GetSize()       
    newCanvasXSize = size.GetWidth() - MIN_BUT_SIZE
    newCanvasYSize = size.GetHeight() - 40
    self.canvas.SetSize((newCanvasXSize, newCanvasYSize))
    self.Layout()

However this doesnt work and my canvas stays the same size as before. I’ve read somewhere that SetSizerAndFit also sets the min_size and that is why resizing doesnt work with it. However, even if I leave it with SetSizer, and resize the frame so everything is positioned properly, the resizing of the canvas doesnt work. Deleting and creating the GLCanvas is not and option here since it takes quite some time to load my vertices.

EDIT

Ok using SetSizer + Layout gets the positioning done. However the Canvas still doesnt resize properly. I have a OnResize binded to EVT_SIZE in the canvas that does:

def OnResize(self, e):
    self.width, self.height = e.GetSize()
    self.SetSize((self.width, self.height))
    self.Layout()

I printed the self.width and self.height here to see what happens. The display is like this:

875 674 — (these are the values that are correct, but immediately after followed by)
640 520 — (these are the default values the Canvas was created with)

This patters repeats itself for every resize.

EDIT2

Ok the above behaviour was because I still had a SetSizerAndFit in a part of my program. If I go for a pure SetSizer + Layout approach this is what happens. The components ( my GLCanvas and 3 other buttons) are added to the frame in their corresponding locations. However:
1.The frame is not resized to the needed size so my buttons are somewhere outside the frame.
2.The GLCanvas is positioned but it doesnt display anything UNTIL I do a resize event myself.

3.Maybe not dirrectly connected but it is possible to decrease min size? I’m asking because if I use SetMinSize() in the Resize handler on the canvas it resizes ONLY WHEN the size increases. If frame size decreases the canvas remains with the old(larger) min size.

EDIT3

Ok after some tweaking I managed to get my canvas to resize with the frame. But now I have another problem, I have a flex grid sizer with one canvas, and three buttons that looks like this:

http://postimage.org/image/1cyhqqcck/

Now I’ve managed to make my canvas resize with the frame, however the Points, Triangle and Go Back buttons stay on the same position when resizing and the canvas just covers them up. I’ve called Layout() with no appearent effect.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T03:09:28+00:00Added an answer on May 23, 2026 at 3:09 am

    As I recall, even Robin Dunn (creator of wxPython) doesn’t use SetSizerAndFit. If you can get the stuff positioned properly when you change the frame size slightly, then you only need to call the frame’s Layout() method. That might be all you need to call to solve the GLCanvas part too. To recap, skip SetSizerAndFit and just use SetSizer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one frame in which one TestArea is there. When I append some
Let's assume that we have a data frame x which contains the columns job
I have the following code which should add a MovieClip and add a frame
I have a UITableView to which I add a tableFooterView , for some reason
I have a frame on which i have created a main panel. On that
I have made a JFrame and inside that frame, there is panel on which
I have a UIButton which i add programmatically. No problems here, it stetches as
I have a data.frame (which I melted using the melt function), from which I
I have a window(say main window) with a frame which has a page in
I have a small frame on my site which has an 'overflow' attribute. All

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.