История изменений
Исправление xxblx, (текущая версия) :
С сайзером всё правильно сделано. В твоем случае просто вместо wx.Notebook проще будет wx.aui.AuiNotebook использовать, телодвижений меньше.
У меня ресайзится всё автоматом при изменении окна.
import wx
import wx.aui
import wx.grid as grid_
class MyFrame(wx.Frame):
def __init__(self, parent=None, id=wx.ID_ANY, pos=wx.DefaultPosition, title='Editor'):
wx.Frame.__init__(self, parent, id, title, pos, (600,600))
# Menu
menuBar = wx.MenuBar()
menu = wx.Menu()
m_eopen = menu.Append(wx.ID_ANY, "&Open file")
m_exit = menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Close window and exit program.")
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnOpen, m_eopen)
self.Bind(wx.EVT_MENU, self.OnClose, m_exit)
# Notebook
self.notebook = wx.aui.AuiNotebook(self, wx.ID_ANY,
style=wx.aui.AUI_NB_DEFAULT_STYLE)
def OnOpen(self, event):
dirname = " "
dlg = wx.FileDialog(self, "Choose a file to open", dirname, " ", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetFilename()
dirname = dlg.GetDirectory()
# Create new tab
tab_panel = wx.Panel( self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
# Create Grid
data_grid = grid_.Grid( tab_panel, wx.ID_ANY, wx.DefaultPosition, tab_panel.GetSize(), wx.HSCROLL|wx.VSCROLL )
data_grid.CreateGrid( 5, 100)
grid_sizer = wx.BoxSizer( wx.HORIZONTAL )
grid_sizer.Add(data_grid, 1 , wx.EXPAND |wx.ALL)
tab_panel.SetSizer(grid_sizer)
self.notebook.InsertPage(0, tab_panel, filename, True)
def OnClose(self, event):
dlg = wx.MessageDialog(self,
"Do you really want to close this application?",
"Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_OK:
self.Destroy()
app = wx.App()
MyFrame(None).Show()
app.MainLoop()
Исправление xxblx, :
Вместо wx.Notebook проще wx.aui.AuiNotebook использовать.
import wx
import wx.aui
import wx.grid as grid_
class MyFrame(wx.Frame):
def __init__(self, parent=None, id=wx.ID_ANY, pos=wx.DefaultPosition, title='Editor'):
wx.Frame.__init__(self, parent, id, title, pos, (600,600))
# Menu
menuBar = wx.MenuBar()
menu = wx.Menu()
m_eopen = menu.Append(wx.ID_ANY, "&Open file")
m_exit = menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Close window and exit program.")
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnOpen, m_eopen)
self.Bind(wx.EVT_MENU, self.OnClose, m_exit)
# Notebook
self.notebook = wx.aui.AuiNotebook(self, wx.ID_ANY,
style=wx.aui.AUI_NB_DEFAULT_STYLE)
def OnOpen(self, event):
dirname = " "
dlg = wx.FileDialog(self, "Choose a file to open", dirname, " ", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetFilename()
dirname = dlg.GetDirectory()
# Create new tab
tab_panel = wx.Panel( self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
# Create Grid
data_grid = grid_.Grid( tab_panel, wx.ID_ANY, wx.DefaultPosition, tab_panel.GetSize(), wx.HSCROLL|wx.VSCROLL )
data_grid.CreateGrid( 5, 100)
grid_sizer = wx.BoxSizer( wx.HORIZONTAL )
grid_sizer.Add(data_grid, 1 , wx.EXPAND |wx.ALL)
tab_panel.SetSizer(grid_sizer)
self.notebook.InsertPage(0, tab_panel, filename, True)
def OnClose(self, event):
dlg = wx.MessageDialog(self,
"Do you really want to close this application?",
"Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_OK:
self.Destroy()
app = wx.App()
MyFrame(None).Show()
app.MainLoop()
Исходная версия xxblx, :
Вместо wx.Notebook проще wx.aui.AuiNotebook использовать.
import wx
import wx.aui
import wx.grid as grid_
class MyFrame(wx.Frame):
def __init__(self, parent=None, id=wx.ID_ANY, pos=wx.DefaultPosition, title='Editor'):
wx.Frame.__init__(self, parent, id, title, pos, (600,600))
# Menu
menuBar = wx.MenuBar()
menu = wx.Menu()
m_eopen = menu.Append(wx.ID_ANY, "&Open file")
m_exit = menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Close window and exit program.")
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
self.Bind(wx.EVT_MENU, self.OnOpen, m_eopen)
self.Bind(wx.EVT_MENU, self.OnClose, m_exit)
# Notebook
self.notebook = wx.aui.AuiNotebook(self, wx.ID_ANY,
style=wx.aui.AUI_NB_DEFAULT_STYLE)
def OnOpen(self, event):
dirname = " "
dlg = wx.FileDialog(self, "Choose a file to open", dirname, " ", "*.*", wx.OPEN)
if dlg.ShowModal() == wx.ID_OK:
filename = dlg.GetFilename()
dirname = dlg.GetDirectory()
# Create new tab
tab_panel = wx.Panel( self.notebook, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.TAB_TRAVERSAL )
# Create Grid
data_grid = grid_.Grid( tab_panel, wx.ID_ANY, wx.DefaultPosition, tab_panel.GetSize(), wx.HSCROLL|wx.VSCROLL )
data_grid.CreateGrid( 5, 100)
grid_sizer = wx.BoxSizer( wx.HORIZONTAL )
grid_sizer.Add(data_grid, 1 , wx.EXPAND |wx.ALL)
tab_panel.SetSizer(grid_sizer)
self.notebook.InsertPage(0, tab_panel, filename, True)
def OnClose(self, event):
dlg = wx.MessageDialog(self,
"Do you really want to close this application?",
"Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_OK:
self.Destroy()
app = wx.App()
MyFrame(None).Show()
app.MainLoop()