无法清除wxBoxSizer的内容

由于某种原因,我sizer.Clear()似乎无法正常工作。

据我从文档中了解到,它应该可以工作。

我做错了什么会导致这种现象吗?

import wx

import os

import sys

import time

import string

import urllib2


class MainWindow(wx.Frame):

  def __init__(self, parent, id=wx.ID_ANY, title="", pos=wx.DefaultPosition,

               size=wx.DefaultSize, style=wx.MINIMIZE_BOX | wx.CLOSE_BOX | wx.RESIZE_BORDER | wx.SYSTEM_MENU | wx.CAPTION):


    wx.Frame.__init__(self, parent, id, title, pos, size, style)

    panel = wx.Panel(self)

    sizer = wx.BoxSizer(wx.VERTICAL)

    panel.SetSizer(sizer)


    self.sizer = sizer

    self.panel = panel


    self.ShowLoginBox()




  def ShowLoginBox(self):

    sizer = wx.FlexGridSizer(rows=4, cols=2, hgap=15, vgap=10)

    sizer.AddGrowableCol(1, 1)


    login_url = wx.TextCtrl(self.panel, 1, size=(150, -1))

    label_url = wx.StaticText(self.panel, -1, "URL:")

    sizer.Add(label_url, 0, wx.LEFT | wx.TOP| wx.RIGHT, 30)

    sizer.Add(login_url, 1, wx.EXPAND | wx.TOP | wx.RIGHT, 30)


    login_username = wx.TextCtrl(self.panel, 1, size=(150, -1))

    label_username = wx.StaticText(self.panel, -1, "Username:")

    sizer.Add(label_username, 0, wx.LEFT | wx.RIGHT, 30)

    sizer.Add(login_username, 1, wx.EXPAND | wx.RIGHT, 30)


    login_password = wx.TextCtrl(self.panel, 1, size=(150, -1), style=wx.TE_PASSWORD)

    label_password = wx.StaticText(self.panel, -1, "Password:")

    sizer.Add(label_password, 0, wx.LEFT | wx.RIGHT, 30)

    sizer.Add(login_password, 1, wx.EXPAND | wx.RIGHT, 30)


    btn_process = wx.Button(self.panel, -1, "&Login")

    self.panel.Bind(wx.EVT_BUTTON, self.OnSubmit, btn_process)

    sizer.Add(btn_process, 0, wx.LEFT, 30)


    login_url.SetValue("http://example.com")

    login_username.SetValue("admin")

    login_password.SetValue("pass")


    self.login_url = login_url

    self.login_username = login_username

    self.login_password = login_password


    self.sizer.Clear()

    self.sizer.Add(sizer, 1, wx.EXPAND)

    self.SetSizeWH(330, 250)

    self.Center()


九州编程
浏览 207回答 1
1回答
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python