wxWidgets 计算不正确的帧大小
我需要制作小的 wxWidgets (wxPython) 框架,它只包含工具栏和菜单栏,并且足够大以容纳它们。当我运行下面的代码时,它会创建一个框架,但它太大了。我应该怎样做才能使框架与它所包含的组件紧密贴合?
创建有问题的框架的代码:
class ToolFrame(wx.Frame):
def __init__(self, editor):
wx.Frame.__init__(self, None, title = "Tools")
self.editor = editor
self.menu = FileMenu(self, editor)
self.menuBar = wx.MenuBar()
self.menuBar.Append(self.menu, "File")
self.SetMenuBar(self.menuBar)
self.toolBar = Tools(self, editor)
self.SetToolBar(self.toolBar)
# frame size has to be constant
self.Layout()
size = self.GetSize()
self.SetMaxSize(size)
self.SetMinSize(size)
# connect exit callback
self.Bind(wx.EVT_CLOSE, self.onClose)
def addTool(self, tool):
self.toolBar.addTool(tool)
def onClose(self, event):
if self.editor:
self.editor.postEvent(events.ExitRequestEvent())
def quit(self):
self.Destroy()
I need to make small wxWidgets (wxPython) frame, which contains only toolbar and menubar and is just enough big to contain them. When I run code below, it creates a frame but it`s way too big. What should I do to make frame fit tightly around components it contains?
Code that creates problematic frame:
class ToolFrame(wx.Frame):
def __init__(self, editor):
wx.Frame.__init__(self, None, title = "Tools")
self.editor = editor
self.menu = FileMenu(self, editor)
self.menuBar = wx.MenuBar()
self.menuBar.Append(self.menu, "File")
self.SetMenuBar(self.menuBar)
self.toolBar = Tools(self, editor)
self.SetToolBar(self.toolBar)
# frame size has to be constant
self.Layout()
size = self.GetSize()
self.SetMaxSize(size)
self.SetMinSize(size)
# connect exit callback
self.Bind(wx.EVT_CLOSE, self.onClose)
def addTool(self, tool):
self.toolBar.addTool(tool)
def onClose(self, event):
if self.editor:
self.editor.postEvent(events.ExitRequestEvent())
def quit(self):
self.Destroy()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试删除 self.SetMaxSize(size) 并说出发生了什么。
Try to delete
self.SetMaxSize(size)
and say what happened.