how to stop growing width of window when child sizers width increased in wx.Dialog in wxpython

人盡茶涼 提交于 2019-12-14 03:22:05

问题


I am very new to wxpython and wxwidgets.I have the code for wx.Dialog like below.

def __init__(self, parent, Name, Platform):
    wx.Dialog.__init__(self, parent, -1, 'Launch Dialog', size=(-1,-1), pos=(-1,-1))
     ###some code 
    self.createSizers()
    self.Fit() 

def createSizers()
    self.mainSizer = wx.BoxSizer(wx.VERTICAL)
    SelectionSizer = wx.StaticBoxSizer(self.staticBoxTestSelection, wx.VERTICAL)
    self.horzDetailsSizer = wx.BoxSizer(wx.HORIZONTAL) 
    self.DetailsSizer = wx.BoxSizer(wx.VERTICAL)
    ### add func here

    self.ListingSizer = wx.BoxSizer(wx.VERTICAL)
    ### add func here

     # Horizontal Splitter
    self.horzDetailsSizer.Add(self.ListingSizer, 3, wx.EXPAND)
    self.horzDetailsSizer.AddSpacer(5)
    self.horzDetailsSizer.Add(self.DetailsSizer, 2, wx.EXPAND)

    # Add subsizers to main
    SelectionSizer.Add(self.horzDetailsSizer, 1, wx.EXPAND | wx.ALL, 5)

    self.mainSizer.Add(SelectionSizer, 0, wx.EXPAND | wx.LEFT | wx.RIGHT, 5)

     ### Initialize mainSize
    self.SetSizer(self.mainSizer)

Here the problem is when the statictextctrl sizers or listctrl sizers of self.DetailsSizer increase width of whole window size and also subsizers width is increasing on right side of window.

I wish to fix the dialog box size and the subsizers should adjust within the window size.That is if one subsizer width is increased, adjacent subsizer should adjust with the space..

Is there any way to do that? Please help me to get rid of this issue.

EDIT:

This is not about user resizing the dialog window..it is about the width of dialog box dynamically growing horizontally.

For ex. in my dialog box I have 2 box sizers named as listing and details adjacent to each other in the window of default size(-1,-1).

In details box I am displaying 'name' dynamically which is related to selected option from listing sizer..So the length of 'name' will change every time..If the length is more and the string is a single word the width of details sizer is increased horizontally so that listing sizer increased.So main sizer of window increased like below.

I do not want this growing and again coming to normal window.The window size should always fix and in case of 'name' length increased in details sizer ,the listing sizer should shrink and adjust with the detail sizer.

Normal Dialog box:

Dynamically width increased:

Desired output to be:


回答1:


Maybe you need to add a sizer without proportion. Look at this code

# Horizontal Splitter
self.horzDetailsSizer.Add(self.ListingSizer, 3, wx.EXPAND) # This Line need to be changed
self.horzDetailsSizer.AddSpacer(5)
self.horzDetailsSizer.Add(self.DetailsSizer, 2, wx.EXPAND)

When you put the proportion 0, the children will not grow on x axis, only in y axis (Because the wx.EXPAND is used). Try to change like code bellow

self.horzDetailsSizer.Add(self.ListingSizer, 0, wx.EXPAND)

This blog (http://www.blog.pythonlibrary.org/2013/11/06/wxpython-101-using-frame-styles) have an explanation to wx Flags. To make a Dialog without resize try to put:

class TestDialog(wx.Dialog):
    def __init__(self,parent)
        dialogStyle = wx.DEFAULT_DIALOG_STYLE& ~ (wx.RESIZE_BORDER | wx.RESIZE_BOX | wx.MAXIMIZE_BOX)
        wx.Dialog.__init__(self, parent, -1, style=dialogStyle)



回答2:


I'm not sure I understand your question, but you're calling Fit() so that your dialog width is set to whatever best fits its contents. If you don't want this to happen, as I interpreted your question, just don't call Fit(). Of course, this may result in the dialog being too narrow to show everything inside it, which is why calling Fit() usually is a good idea, but it's your choice whether to do it or not.



来源:https://stackoverflow.com/questions/37112551/how-to-stop-growing-width-of-window-when-child-sizers-width-increased-in-wx-dial

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!