How can I know if a widget is shown or not?
"self.IsShown" is for window.
Widgets inherit from wx.Window so they have the IsShown method
import wx
from wx.lib import sized_controls
class TestFrame(sized_controls.SizedFrame):
def __init__(self, *args, **kwargs):
super(TestFrame, self).__init__(*args, **kwargs)
pane = self.GetContentsPane()
self.btn = wx.Button(pane, label='Hide')
self.btn.Bind(wx.EVT_BUTTON, self.on_btn)
self.btn_hidden = wx.Button(pane, label='Hidden?')
self.s_txt = wx.StaticText(pane, label='Button shown: True')
def on_btn(self, event):
is_shown = not self.btn_hidden.IsShown()
self.btn_hidden.Show(is_shown)
self.s_txt.SetLabel('Button shown: {}'.format(is_shown))
if is_shown:
self.btn.SetLabel('Hide')
else:
self.btn.SetLabel('Show')
if __name__ == '__main__':
wxapp = wx.App(False)
main_app_frame = TestFrame(None)
main_app_frame.Show()
wxapp.MainLoop()
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.