Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 在另一个窗框中保留一个窗框_Python 2.7_Window_Wxpython_Frame - Fatal编程技术网

Python 2.7 在另一个窗框中保留一个窗框

Python 2.7 在另一个窗框中保留一个窗框,python-2.7,window,wxpython,frame,Python 2.7,Window,Wxpython,Frame,我的程序在一个水平的boxsizer中创建一个包含三个面板的框架。带有“新建窗口”项的菜单,用于创建第二个框架。我将seconde面板作为seconde窗口的父级。我希望第二帧保留在第一帧的第二面板区域。 如果用户移动两个窗口中的一个,则第二个窗口将停留在面板屏幕区域。 你知道怎么做吗? 我尝试了一些东西,但使用起来不太美观 及 导入wx 类主窗口(wx.Frame): 定义初始化(自身、父项、id): Frame.\uuuuu init\uuuuuuuuuux(self,parent,id,'

我的程序在一个水平的boxsizer中创建一个包含三个面板的框架。带有“新建窗口”项的菜单,用于创建第二个框架。我将seconde面板作为seconde窗口的父级。我希望第二帧保留在第一帧的第二面板区域。 如果用户移动两个窗口中的一个,则第二个窗口将停留在面板屏幕区域。 你知道怎么做吗? 我尝试了一些东西,但使用起来不太美观

导入wx
类主窗口(wx.Frame):
定义初始化(自身、父项、id):
Frame.\uuuuu init\uuuuuuuuuux(self,parent,id,'Python测试应用程序',大小=(600400))
#小部件
面板(自-1,尺寸=(150,-1))
面板\u gch.立根基色(“白色”)
self.panel=wx.panel(self,-1,大小=(300400))
自嵌板立根底色((200230200))
面板(自-1,尺寸=(150,-1))
面板图纸立根底色(“白色”)
box=wx.BoxSizer(wx.水平)
自动设定器(盒)
#加
添加(面板,0,wx.展开)
添加(自面板,1,wx.展开)
添加(面板0,wx.展开)
#菜单
status=self.CreateStatusBar()
menubar=wx.menubar()
file_menu=wx.menu()
ID\u文件\u新建=1
文件\菜单.Append(ID \文件\新,“新窗口”,“这是一个新窗口”)
menubar.Append(文件菜单,“文件”)
self.SetMenuBar(menubar)
#装订和布局
self.Bind(wx.EVT_菜单,self.get_新窗口)
面板总布置图()
self.panel.Layout()
面板图纸布局()
self.Layout()
def获取新窗口(自身、事件):#创建新窗口
self.new=NewWindow(self.panel,-1)
self.new.Show(真)
self.new.Bind(wx.EVT\u移动,self.window2\u移动)
def window2正在移动(自身、事件):#window2必须保持在
x、 y=事件。GetPosition()
v、 w=self.panel.GetScreenPosition()
s、 t=self.panel.GetClientSizeTuple()
如果xv+s:
自新移动((v+s-200,-1))
如果y+200>w+t:
自新移动(-1,w+t-200))
类新窗口(wx.MiniFrame):
def u u init _;(self,主窗口,id):
wx.MiniFrame.\uuuuu init\uuuuuuuux(self,main Window,id,'New Window',size=(200200)\
样式=wx.MINIMIZE | wx.CAPTION | wx.CLOSE_BOX | wx.CLOSE_BOX)
self.CenterOnParent()
如果“名称”=“\uuuuuuuu主要”:
app=wx.PySimpleApp()
frame=MainWindow(父窗口=None,id=-1)
frame.Show()
app.MainLoop()

您可能需要的是AUI。我个人推荐wx.lib.agw.aui集,而不是wx.aui集,因为前者是纯Python的,并且最近已经做了很多工作。wxPython演示包中有多个示例。您也可以在此处阅读:


    • 非常感谢你,迈克,这正是我需要的

      对于wxpython,我发现了以下方法: 子对象停留在面板区域中,移动时跟随窗口父对象

      import wx
      
      class MainWindow(wx.Frame):
      
          def __init__(self,parent,id):
              wx.Frame.__init__(self,parent,id,'Python Test App',size=(600,400))
              self.new = None
              #Widgets
              self.position = (0,0)
              panel_gch = wx.Panel(self,-1,size = (150,-1))
              panel_gch.SetBackgroundColour('white')
              self.panel=wx.Panel(self,-1,size=(300,400))
              self.panel.SetBackgroundColour((200,230,200))
              panel_drt = wx.Panel(self,-1,size = (150,-1))
              panel_drt.SetBackgroundColour('white')
              box = wx.BoxSizer(wx.HORIZONTAL)
              self.SetSizer(box)
      
              #Add
              box.Add(panel_gch,0,wx.EXPAND)
              box.Add(self.panel,1,wx.EXPAND)
              box.Add(panel_drt,0,wx.EXPAND)
      
              #Menu
              status=self.CreateStatusBar()
              menubar=wx.MenuBar()
              file_menu=wx.Menu()
              ID_FILE_NEW = 1
              file_menu.Append(ID_FILE_NEW,"New Window","This is a new window")
              menubar.Append(file_menu,"File")
              self.SetMenuBar(menubar)
      
              #bind and layout
              self.Bind(wx.EVT_MENU, self.get_new_window)
      
              panel_gch.Layout()
              self.panel.Layout()
              panel_drt.Layout()
              self.Layout()
      
          def get_new_window(self,event): # create new window
              if self.new == None:
                  self.win_one_move = False
                  self.new = NewWindow(self.panel,-1)
                  self.new.Show(True)
                  self.new.Bind(wx.EVT_MOVE,self.window2_on_move)
                  self.Bind(wx.EVT_MOVE,self.window1_on_move)
                  v,w =self.GetPosition()
                  x, y = self.new.GetPosition()                
                  self.get_windows_position((x-v),(y-w))       
      
      
          def get_windows_position(self,x,y):
              self.position = (x,y)
              print "check",self.position
      
          def window2_on_move(self,event): # Window2 must stay in
              if self.win_one_move == False:
                  x, y = event.GetPosition()
                  v,w =self.panel.GetScreenPosition()
                  s,t = self.panel.GetClientSizeTuple()
                  new_x,new_y = self.new.GetClientSizeTuple()
                  if x < v:
                      self.new.Move((v,-1))
                  if y < w:
                      self.new.Move((-1,w))
                  if x+new_x > v+s:
                      self.new.Move((v+s-new_x,-1))
                  if y+new_y > w+t:
                      self.new.Move((-1,w+t-new_y))
                  v,w =self.GetPosition()
                  x,y = self.new.GetPosition() 
                  self.get_windows_position((x-v),(y-w))
              if self.win_one_move == True:
      
                  self.win_one_move = False
      
          def window1_on_move(self,event):
              self.win_one_move = True
              print "1 move"
              x,y = self.GetPosition()
              self.new.Move((x+self.position[0],y+self.position[1]))        
              print self.position
      
      
      class NewWindow(wx.MiniFrame):
      
          def __init__(self,MainWindow,id):
              wx.MiniFrame.__init__(self, MainWindow, id, 'New Window', size=(200,200),\
                                    style = wx.CAPTION | wx.CLOSE_BOX | wx.CLOSE_BOX)
              self.CenterOnParent()
      
      
      if __name__=='__main__':
              app=wx.PySimpleApp()
              frame=MainWindow(parent=None,id=-1)
              frame.Show()
              app.MainLoop()
      
      导入wx
      类主窗口(wx.Frame):
      定义初始化(自身、父项、id):
      Frame.\uuuuu init\uuuuuuuuuux(self,parent,id,'Python测试应用程序',大小=(600400))
      self.new=无
      #小部件
      self.position=(0,0)
      面板(自-1,尺寸=(150,-1))
      面板\u gch.立根基色(“白色”)
      self.panel=wx.panel(self,-1,大小=(300400))
      自嵌板立根底色((200230200))
      面板(自-1,尺寸=(150,-1))
      面板图纸立根底色(“白色”)
      box=wx.BoxSizer(wx.水平)
      自动设定器(盒)
      #加
      添加(面板,0,wx.展开)
      添加(自面板,1,wx.展开)
      添加(面板0,wx.展开)
      #菜单
      status=self.CreateStatusBar()
      menubar=wx.menubar()
      file_menu=wx.menu()
      ID\u文件\u新建=1
      文件\菜单.Append(ID \文件\新,“新窗口”,“这是一个新窗口”)
      menubar.Append(文件菜单,“文件”)
      self.SetMenuBar(menubar)
      #装订和布局
      self.Bind(wx.EVT_菜单,self.get_新窗口)
      面板总布置图()
      self.panel.Layout()
      面板图纸布局()
      self.Layout()
      def获取新窗口(自身、事件):#创建新窗口
      如果self.new==无:
      self.win\u one\u move=False
      self.new=NewWindow(self.panel,-1)
      self.new.Show(真)
      self.new.Bind(wx.EVT\u移动,self.window2\u移动)
      self.Bind(wx.EVT\u移动,self.window1\u移动)
      v、 w=self.GetPosition()
      x、 y=self.new.GetPosition()
      自动获取窗口位置((x-v)、(y-w))
      def获取窗口位置(自身、x、y):
      self.position=(x,y)
      打印“检查”,自我定位
      def window2正在移动(自身、事件):#window2必须保持在
      如果self.win\u one\u move==False:
      x、 y=事件。GetPosition()
      v、 w=self.panel.GetScreenPosition()
      s、 t=self.panel.GetClientSizeTuple()
      new_x,new_y=self.new.GetClientSizeTuple()
      如果xv+s:
      self.new.Move((v+s-new_x,-1))
      如果y+new_y>w+t:
      自新移动((-1,w+t-new_y))
      v、 w=self.GetPosition()
      x、 y=self.new.GetPosition()
      自动获取窗口位置((x-v)、(y-w))
      如果self.win\u one\u move==True:
      self.win\u one\u move=False
      def window1打开移动(自身、事件):
      self.win\u one\u move=正确
      打印“1步”
      x、 y=self.GetPosition()
      self.new.Move((x+self.position[0],y+self.position[1]))
      打印自我定位
      类新窗口(wx.MiniFrame):
      def u u init _;(self,主窗口,id):
      wx.MiniFrame.\uuuu init
      
      import wx
      
      class MainWindow(wx.Frame):
      
          def __init__(self,parent,id):
              wx.Frame.__init__(self,parent,id,'Python Test App',size=(600,400))
              self.new = None
              #Widgets
              self.position = (0,0)
              panel_gch = wx.Panel(self,-1,size = (150,-1))
              panel_gch.SetBackgroundColour('white')
              self.panel=wx.Panel(self,-1,size=(300,400))
              self.panel.SetBackgroundColour((200,230,200))
              panel_drt = wx.Panel(self,-1,size = (150,-1))
              panel_drt.SetBackgroundColour('white')
              box = wx.BoxSizer(wx.HORIZONTAL)
              self.SetSizer(box)
      
              #Add
              box.Add(panel_gch,0,wx.EXPAND)
              box.Add(self.panel,1,wx.EXPAND)
              box.Add(panel_drt,0,wx.EXPAND)
      
              #Menu
              status=self.CreateStatusBar()
              menubar=wx.MenuBar()
              file_menu=wx.Menu()
              ID_FILE_NEW = 1
              file_menu.Append(ID_FILE_NEW,"New Window","This is a new window")
              menubar.Append(file_menu,"File")
              self.SetMenuBar(menubar)
      
              #bind and layout
              self.Bind(wx.EVT_MENU, self.get_new_window)
      
              panel_gch.Layout()
              self.panel.Layout()
              panel_drt.Layout()
              self.Layout()
      
          def get_new_window(self,event): # create new window
              if self.new == None:
                  self.win_one_move = False
                  self.new = NewWindow(self.panel,-1)
                  self.new.Show(True)
                  self.new.Bind(wx.EVT_MOVE,self.window2_on_move)
                  self.Bind(wx.EVT_MOVE,self.window1_on_move)
                  v,w =self.GetPosition()
                  x, y = self.new.GetPosition()                
                  self.get_windows_position((x-v),(y-w))       
      
      
          def get_windows_position(self,x,y):
              self.position = (x,y)
              print "check",self.position
      
          def window2_on_move(self,event): # Window2 must stay in
              if self.win_one_move == False:
                  x, y = event.GetPosition()
                  v,w =self.panel.GetScreenPosition()
                  s,t = self.panel.GetClientSizeTuple()
                  new_x,new_y = self.new.GetClientSizeTuple()
                  if x < v:
                      self.new.Move((v,-1))
                  if y < w:
                      self.new.Move((-1,w))
                  if x+new_x > v+s:
                      self.new.Move((v+s-new_x,-1))
                  if y+new_y > w+t:
                      self.new.Move((-1,w+t-new_y))
                  v,w =self.GetPosition()
                  x,y = self.new.GetPosition() 
                  self.get_windows_position((x-v),(y-w))
              if self.win_one_move == True:
      
                  self.win_one_move = False
      
          def window1_on_move(self,event):
              self.win_one_move = True
              print "1 move"
              x,y = self.GetPosition()
              self.new.Move((x+self.position[0],y+self.position[1]))        
              print self.position
      
      
      class NewWindow(wx.MiniFrame):
      
          def __init__(self,MainWindow,id):
              wx.MiniFrame.__init__(self, MainWindow, id, 'New Window', size=(200,200),\
                                    style = wx.CAPTION | wx.CLOSE_BOX | wx.CLOSE_BOX)
              self.CenterOnParent()
      
      
      if __name__=='__main__':
              app=wx.PySimpleApp()
              frame=MainWindow(parent=None,id=-1)
              frame.Show()
              app.MainLoop()