Hi.
Well, I am newbie with wxpython…sorry
.
I am trying to add a textctrl in a toolbar but filled.
And I can not.
This is the example code:
···
#!/usr/bin/env python
import wx
class MainWindow(wx.Frame):
def init(self, parent, ID, title):
wx.Frame.init(self, parent, wx.ID_ANY, title)
panel = wx.Panel(self, wx.ID_ANY)
text = wx.StaticText(panel, wx.ID_ANY, “Hello, World!”, wx.Point(10, 5), wx.Size(-1, -1))
self.toolbar = self.CreateToolBar()
self.toolbar.AddSeparator()
text = wx.TextCtrl(self.toolbar, size=(140, -1))
hbox = wx.BoxSizer(wx.HORIZONTAL)
hbox.Add(text, 1, wx.EXPAND | wx.ALL)
self.toolbar.AddControl(hbox)
self.toolbar.Realize()
menubar = wx.MenuBar()
fileMenu = wx.Menu()
fitem = fileMenu.Append(wx.ID_EXIT, 'Quit', 'Quit application')
menubar.Append(fileMenu, '&File')
self.SetMenuBar(menubar)
self.Bind(wx.EVT_MENU, self.OnQuit, fitem)
def OnQuit(self, e):
self.Close()
class Test(wx.App):
def OnInit(self):
frame = MainWindow(None, wx.ID_ANY, “test”)
self.SetTopWindow(frame)
frame.Show(True)
return True
if name == ‘main’:
app = Test()
app.MainLoop()
Regards and thanks.
Hi Miguel,
When running your sample I get:
File "D:\devOther\samplesTest\MiguelMatias\tbwithtc.py", line 45, in <module>
app = Test()
File "c:\Python34\Lib\site-packages\wx\core.py", line 1864, in __init__
self._BootstrapApp()
 File "D:\devOther\samplesTest\MiguelMatias\tbwithtc.py", line 37, in OnInit
frame = MainWindow(None, wx.ID_ANY, "test")
 File "D:\devOther\samplesTest\MiguelMatias\tbwithtc.py", line 21, in __init__
self.toolbar.AddControl(hbox)
builtins.TypeError: ToolBar.AddControl(): argument 1 has unexpected type 'BoxSizer'
Which gives you a hint, i.e. a BoxSizer is not a control, while using sizers in general is a very good idea but you don't need that with the ToolBar. Just add your 'text' to the toolbar, e.g.:
self.toolbar.AddControl(text)
See also: wxpython.org/Phoenix/docs/html/ToolBar.html
Werner
Yes, thanks.
But how I can set the textCtrl to fit all horizontal size in toolbar?
Regards.
···
2015-03-13 10:52 GMT+01:00 Werner wernerfbd@gmx.ch:
Hi Miguel,
When running your sample I get:
File “D:\devOther\samplesTest\MiguelMatias\tbwithtc.py”, line 45, in
app = Test()
File “c:\Python34\Lib\site-packages\wx\core.py”, line 1864, in init
self._BootstrapApp()
 File “D:\devOther\samplesTest\MiguelMatias\tbwithtc.py”, line 37, in OnInit
frame = MainWindow(None, wx.ID_ANY, “test”)
 File “D:\devOther\samplesTest\MiguelMatias\tbwithtc.py”, line 21, in init
self.toolbar.AddControl(hbox)
builtins.TypeError: ToolBar.AddControl(): argument 1 has unexpected type ‘BoxSizer’
Which gives you a hint, i.e. a BoxSizer is not a control, while using sizers in general is a very good idea but you don’t need that with the ToolBar. Just add your ‘text’ to the toolbar, e.g.:
self.toolbar.AddControl(text)
See also: wxpython.org/Phoenix/docs/html/ToolBar.html
Werner
–
You received this message because you are subscribed to the Google Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.