Python论坛  - 讨论区

标题:[python-chinese] [wxPython] wxsizer Layout doesn't work after Detach

2005年11月19日 星期六 16:37

zhang yunfeng zhangyunfeng at gmail.com
Sat Nov 19 16:37:36 HKT 2005

Hi, sorry for my chinese input method doesn' t  work now.

I'd like to delete and add some controls on wxPanel dynamically. I use
wxSizer.Detach() and Layout(), but it doesn't work at all, as the
following code shows. If the control(say self.btn) in sizer has nonzero
proportion, it works fine. But I wish the button stays non-expand, any
way ? or any wrong usage of sizer?

Zhang

--------------------------------------------------------
import wx
class Form1(wx.Panel):
    def __init__(self,parent,id):
        wx.Panel.__init__(self,parent,id)

        self.btn = wx.Button(self, -1, 'go')
        self.sizer = wx.BoxSizer(wx.VERTICAL)

        self.sizer.Add(self.btn)         ## it doesn't work
        # self.sizer.Add(self.btn, 1)    ## it works

        self.p1 = wx.StaticText(self, -1, 'ppp1')
        self.sizer.Add(self.p1)

        self.SetSizer(self.sizer)
        self.SetAutoLayout(True)

        self.btn.Bind(wx.EVT_BUTTON, self.onbtn)

    def onbtn(self,event):
        self.sizer.Detach(self.p1)
        self.sizer.Layout()

app = wx.PySimpleApp()
frame = wx.Frame(None, -1, "Test")
Form1(frame,-1)
frame.Show(1)
app.MainLoop()

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年11月19日 星期六 19:38

Qiangning Hong hongqn at gmail.com
Sat Nov 19 19:38:27 HKT 2005

zhang yunfeng wrote:
> Hi, sorry for my chinese input method doesn' t  work now.
> 
> I'd like to delete and add some controls on wxPanel dynamically. I use
> wxSizer.Detach() and Layout(), but it doesn't work at all, as the
> following code shows. If the control(say self.btn) in sizer has nonzero
> proportion, it works fine. But I wish the button stays non-expand, any
> way ? or any wrong usage of sizer?
> 
[略]
>     def onbtn(self,event):
>         self.sizer.Detach(self.p1)

在这里加上 self.p1.Destroy()

>         self.sizer.Layout()

[略]


-- 
Qiangning Hong, Registered Linux User #396996
My Blog: http://www.hn.org/hongqn
RSS: http://feeds.feedburner.com/hongqn


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

2005年11月20日 星期日 15:22

zhang yunfeng zhangyunfeng at gmail.com
Sun Nov 20 15:22:08 HKT 2005

多谢,好用了,只是看起来有点儿闪动,有什么办法解决吗?

2005/11/19, Qiangning Hong <hongqn at gmail.com>:
> zhang yunfeng wrote:
> > Hi, sorry for my chinese input method doesn' t  work now.
> >
> > I'd like to delete and add some controls on wxPanel dynamically. I use
> > wxSizer.Detach() and Layout(), but it doesn't work at all, as the
> > following code shows. If the control(say self.btn) in sizer has nonzero
> > proportion, it works fine. But I wish the button stays non-expand, any
> > way ? or any wrong usage of sizer?
> >
> [略]
> >     def onbtn(self,event):
> >         self.sizer.Detach(self.p1)
>
> 在这里加上 self.p1.Destroy()
>
> >         self.sizer.Layout()
>
> [略]
>
>

[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2025

    京ICP备05028076号