0

wxpython でメニュー バー付きのフレームを作成し、メインのサイザーをフレーム自体の子として設定しましたが、フレームのサイズを変更した後、フレームのパネルは固定サイズのままです。メニューバーを削除し、メインサイザーをパネル自体に設定すると、サイズ変更は完全に機能しますが、メニューをフレームに追加すると、メインサイザーをパネルに設定すると機能しません。

tl;dr - このコードのパネル サイズは固定のままです。サイズ変更可能にするにはどうすればよいですか?

import wx

class Mainframe(wx.Frame):
def __init__(self,parent,title):
    wx.Frame.__init__(self,parent,title=title,size=(650,450))
    self.Main_Panel = wx.Panel(self,id=wx.ID_ANY)

    #################################################################
    ### Template menubar menubar
    #################################################################
    Menubar = wx.MenuBar()
    Filemenu = wx.Menu()
    Debugmenu = wx.Menu()

    self.Menu_Open_File = Filemenu.Append(wx.ID_OPEN,"Open","Open an nrix file to edit")
    self.Menu_SaveAs_File = Filemenu.Append(wx.ID_SAVEAS,"Save as","Normal saving will be incorporated later")
    Filemenu.AppendSeparator()
    self.Menu_About_Dialog = Filemenu.Append(wx.ID_ABOUT,"About","Information about the program and changelog")
    self.Debug_State_Switch = Debugmenu.Append(wx.ID_ANY,"Debug on","Turn on debug mode",wx.ITEM_CHECK)

    Menubar.Append(Filemenu,"File")
    Menubar.Append(Debugmenu,"Debug")
    self.SetMenuBar(Menubar)
    #################################################################
    ### Frame objects
    #################################################################
    Left_Static_text = wx.StaticText(self.Main_Panel,wx.ID_ANY,style=wx.ALIGN_LEFT)
    Left_Static_text.SetFont(wx.Font(16,wx.ROMAN,wx.NORMAL,wx.FONTWEIGHT_NORMAL))
    Left_Static_text.SetLabel("Exploitable text")

    Left_Text_Control = wx.TextCtrl(self.Main_Panel,wx.ID_ANY,value="Exploitable")

    Buttons = []
    for i in range(4):
        Buttons.append(wx.Button(self.Main_Panel,label=str(i + 1),size=(50,50)))
    #################################################################
    ### Frame sizers
    #################################################################
    Grid_Sizer = wx.GridSizer(2,2,15,15)
    Ver_Wrapper = wx.BoxSizer(wx.VERTICAL)
    Left_Sizer = wx.BoxSizer(wx.VERTICAL)
    Whole_Sizer = wx.BoxSizer(wx.HORIZONTAL)
    #################################################################
    ### Attaching sizers
    #################################################################
    for i in range(4):
        Grid_Sizer.Add(Buttons[i],0,wx.EXPAND)

    Ver_Wrapper.Add((0,0),proportion=1,flag=wx.EXPAND)
    Ver_Wrapper.Add(Grid_Sizer,proportion=0,flag=wx.CENTER)
    Ver_Wrapper.Add((0,0),proportion=1,flag=wx.EXPAND)

    Left_Sizer.Add((0,0),proportion=1,flag=wx.EXPAND)
    Left_Sizer.Add(Left_Static_text,proportion=0,flag=wx.CENTER)
    Left_Sizer.Add(Left_Text_Control,proportion=0,flag=wx.CENTER)
    Left_Sizer.Add((0,0),proportion=1,flag=wx.EXPAND)

    Whole_Sizer.Add(Left_Sizer,proportion=1,flag=wx.EXPAND)
    Whole_Sizer.Add(Ver_Wrapper,proportion=3,flag=wx.EXPAND)

    # self.Main_Panel.SetSizer(Whole_Sizer) <- THIS WORKS WITHOUT A MENU
    self.SetSizer(Whole_Sizer)

app = wx.App(False)
frame = Mainframe(None,"Menu UI")
frame.Show(True)
app.MainLoop()
4

1 に答える 1