Main window sizing incorrectly

Hi All,

I’m seeing some weirdness when I run my app on Windows. To wit, the screen looks like this on the Mac:

but on Windows it looks like this:

The code for the main window is:

import os
import glob
import wx
import wx.grid
from MainPanel import MainPanel


class MainFrame(wx.Frame):

    def __init__(self):
        flags = wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.MAXIMIZE_BOX)
        super().__init__(None, title='Spreadsheet Scorer', style=flags,
                         size=wx.Size(765, 440))
        
        panel = MainPanel(self)
        self.Bind(wx.EVT_BUTTON, self.__on_close, id=wx.ID_EXIT)
        self.Show()

    def __on_close(self, event):
        """ Close the application """
        self.Destroy()


if __name__ == '__main__':
    app = wx.App(redirect=False)
    frame = MainFrame()
    app.MainLoop()

and the MainPanel (less the helper functions) is:

class MainPanel(wx.Panel):

    def __init__(self, parent):
        """
        Class constructor
        """
        super().__init__(parent)

        self.default_adj_vals = {'Plus_2x': '+2', 'Plus_1x': '+1',
                                 'No Change': '0', 'Minus_1x': '-1',
                                 'Minus_2x': '-2'}
        self.default_comp_code_vals = {'FCN': '10', 'CFCC': '8',
                                       'CFNotCC': '5', 'NC': '0'}
        self.default_priority_code_vals = {'H': '1.0', 'M': '0.6', 'L': '0.3'}

        self.__init_values()

        self.main_sizer = wx.BoxSizer()
        self.__add_left_pane()
        self.__add_right_pane()
        self.main_panel_size = self.main_sizer.GetMinSize()
        self.SetSizer(self.main_sizer)

I’m sure it’s likely something that I’m not doing quite correctly but I have no clue why the screen would display differently on Windows than it does on the Mac. FWIW, the panes are being added to the main_sizer in their respective methods.

Thanks for any insights!

Chuck

I changed the MainFrame init method to do the following and that somehow seems to have fixed things although I can’t fathom why I need to add an extra 20 pixels to the height. :slightly_frowning_face:

    def __init__(self):
        flags = wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.MAXIMIZE_BOX)
        super().__init__(None, title='Spreadsheet Scorer', style=flags,
                         size=wx.Size(765, 450))
        panel = MainPanel(self)
        size = panel.main_panel_size
        width = size[0]
        height = size[1]+20
        self.SetSize((width, height))
        self.Fit()
        self.Bind(wx.EVT_BUTTON, self.__on_close, id=wx.ID_EXIT)
        self.Show()

What is the question?
Widgets, borders etc. have different sizes on different platforms.
For specific problems, attach a running sample. Nobody will assemble a running program from posted samples to solve your problem.

I am attempting to determine why the application is displayed differently on Windows that what it is on the Mac (see pics above). Same code but different outcomes.

The main panel gets two panes as children. Each pane has a collection of controls. The behavior on Windows appears to be that the sizer with the buttons is not being recognized when the application frame is sized. I’ve tried a number of different things to try to correctly set the application window size, but alas, all have ultimately failed. I’m left with a brute force method that checks for the operating system and manually corrects for the issue but as you can imagine this is less than ideal.

Curiouser and curiouser. This morning, I dove back into testing and the problem has disappeared…

An easy way to ensure that the frame is sized correctly is to put the frame’s top-level item(s) into a sizer, even if it’s just a single panel like your example, and then call the frame’s Fit method.

Hi Robin,

Thanks, I’ll try that if the problem resurfaces. The diagram below is how I have my sizers and controls laid out. If it’s not labeled as a control, then it’s a sizer. :grin:

Scorer_Sizer_Layout

It was just sort of odd though because I had not experience that behavior before and then just as quickly as it appeared, it disappears. :man_shrugging:

Thanks again!

Charles

P.S. While I’ve used GUI builder tools in the past, I don’t find them to be much easier that doing things by hand because I want to believe that I understand how sizers work from working with wxWidgets several years ago (back when it was still called wxWindows). :grin: