改为创建一个 wx.Dialog。然后您可以使用您提到的 wx.TE_PASSWORD 样式在其上放置一个文本控件。您可以添加一个按钮并将其 id 设置为 wx.ID_OK。像下面这样的东西应该可以工作:
import wx
########################################################################
class LoginDialog(wx.Dialog):
""""""
#----------------------------------------------------------------------
def __init__(self):
"""Constructor"""
wx.Dialog.__init__(self, None, title="Login")
self.mainSizer = wx.BoxSizer(wx.VERTICAL)
btnSizer = wx.BoxSizer(wx.HORIZONTAL)
userLbl = wx.StaticText(self, label="Username:")
userTxt = wx.TextCtrl(self)
self.addWidgets(userLbl, userTxt)
passLbl = wx.StaticText(self, label="Password:")
passTxt = wx.TextCtrl(self, style=wx.TE_PASSWORD)
self.addWidgets(passLbl, passTxt)
okBtn = wx.Button(self, wx.ID_OK)
btnSizer.Add(okBtn, 0, wx.CENTER|wx.ALL, 5)
cancelBtn = wx.Button(self, wx.ID_CANCEL)
btnSizer.Add(cancelBtn, 0, wx.CENTER|wx.ALL, 5)
self.mainSizer.Add(btnSizer, 0, wx.CENTER)
self.SetSizer(self.mainSizer)
#----------------------------------------------------------------------
def addWidgets(self, lbl, txt):
"""
"""
sizer = wx.BoxSizer(wx.HORIZONTAL)
sizer.Add(lbl, 0, wx.ALL|wx.CENTER, 5)
sizer.Add(txt, 1, wx.EXPAND|wx.ALL, 5)
self.mainSizer.Add(sizer, 0, wx.EXPAND)
if __name__ == "__main__":
app = wx.App(False)
dlg = LoginDialog()
dlg.ShowModal()
dlg.Destroy()
app.MainLoop()