当wxpython中的wx.Dialog中的子尺寸器宽度增加时,如何停止窗口宽度的增长 [英] how to stop growing width of window when child sizers width increased in wx.Dialog in wxpython

查看:43
本文介绍了当wxpython中的wx.Dialog中的子尺寸器宽度增加时,如何停止窗口宽度的增长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 wxpython 和 wxwidgets 很陌生.我有 wx.Dialog 的代码,如下所示.

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)

这里的问题是当 self.DetailsS​​izer 的 statictextctrl sizers 或 listctrl sizers 增加整个窗口大小的宽度并且 subsizers 宽度在窗口右侧增加时.

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.

我想固定对话框大小,subsizers应该在窗口大小内调整.也就是说,如果增加一个subsizer宽度,相邻的subsizer应该随着空间调整..

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.

编辑:

这不是关于用户调整对话框窗口的大小......而是关于动态水平增长的对话框宽度.

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

例如.在我的对话框中,我在默认大小(-1,-1)的窗口中有 2 个名为列表和详细信息的框大小器.

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).

在详细信息框中,我正在动态显示名称",它与列表 sizer 中的选定选项相关..所以名称"的长度每次都会改变..如果长度更多并且字符串是单个单词详细信息 sizer 的宽度水平增加,以便列表 sizer 增加.因此窗口的 main sizer 增加如下.

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.

我不希望这种增长并再次进入正常窗口.窗口大小应该始终固定,并且如果名称"长度在 details sizer 中增加,listing sizer 应该缩小并使用 detail sizer 进行调整.

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.

普通对话框:

动态宽度增加:

期望输出:

推荐答案

也许你需要添加一个没有比例的sizer.看看这段代码

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)

当你把比例设为 0 时,孩子不会在 x 轴上生长,只会在 y 轴上生长(因为使用了 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)

这个博客(http://www.blog.pythonlibrary.org/2013/11/06/wxpython-101-using-frame-styles) 对 wx Flags 有解释.要制作一个不调整大小的对话框,请尝试放置:

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)

这篇关于当wxpython中的wx.Dialog中的子尺寸器宽度增加时,如何停止窗口宽度的增长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆