wxPython - 在框架中显示隐藏的工具栏
在本文中,我们将学习如何显示隐藏的工具栏。为了取消隐藏/显示工具栏,我们可以使用 Show()函数。 Show()函数可用于显示和隐藏工具栏。 Show()函数采用 show 布尔参数,如果为 True,则显示窗口。否则,隐藏它。
Syntax: wx.ToolBar.Show(self, show=True)
Parameters:
Parameter | Input Type | Description |
---|---|---|
show | bool | If True displays the window. Otherwise, hides it. |
Return Type: bool
Returns: True if the window has been shown or hidden or False if nothing was done because it already was in the requested state.
代码示例:
import wx
class Example(wx.Frame):
global count
count = 0;
def __init__(self, *args, **kwargs):
super(Example, self).__init__(*args, **kwargs)
self.InitUI()
def InitUI(self):
self.locale = wx.Locale(wx.LANGUAGE_ENGLISH)
self.toolbar = self.CreateToolBar()
tool = self.toolbar.AddTool(wx.ID_ANY, 'First',
wx.Bitmap('right.png'))
self.toolbar.Realize()
# panel for button
self.pnl = wx.Panel(self)
# button to hide toolbar
self.btn = wx.Button(self.pnl, label ='Hide Toolbar', pos =(20, 20))
# button to show toolbar
self.btn2 = wx.Button(self.pnl, label ='Show Toolbar', pos =(200, 20))
# bind event with hide button
self.btn.Bind(wx.EVT_BUTTON, self.onclickhide)
# bind event with show button
self.btn2.Bind(wx.EVT_BUTTON, self.onclickshow)
self.SetSize((350, 250))
self.SetTitle('Simple toolbar')
self.Centre()
def onclickhide(self, e):
# hide toolbar
self.toolbar.Hide()
def onclickshow(self, e):
# hide toolbar
self.toolbar.Show(True)
def main():
app = wx.App()
ex = Example(None)
ex.Show()
app.MainLoop()
if __name__ == '__main__':
main()
输出窗口:
在点击按钮之前
点击按钮后