Skip to content

Instantly share code, notes, and snippets.

@pythonsuezo
Last active June 27, 2018 04:15
Show Gist options
  • Save pythonsuezo/cb8c14c598761b8f6e103b50a23c0650 to your computer and use it in GitHub Desktop.
Save pythonsuezo/cb8c14c598761b8f6e103b50a23c0650 to your computer and use it in GitHub Desktop.
wxpythonのフレームについて色々
# -*- coding: utf-8 -*-
###########################################################################
## Python code generated with wxFormBuilder (version May 29 2018)
## http://www.wxformbuilder.org/
##
## PLEASE DO *NOT* EDIT THIS FILE!
###########################################################################
import wx
import wx.xrc
###########################################################################
## Class MyFrame1
###########################################################################
class MyFrame1 ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = u"テスト用フレーム", pos = wx.DefaultPosition, size = wx.Size( 328,123 ), style = wx.DEFAULT_FRAME_STYLE|wx.TAB_TRAVERSAL )
self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
self.Centre( wx.BOTH )
def __del__( self ):
pass
###########################################################################
## Class MyFrame2
###########################################################################
class MyFrame2 ( wx.Frame ):
def __init__( self, parent ):
wx.Frame.__init__ ( self, parent, id = wx.ID_ANY, title = wx.EmptyString, pos = wx.DefaultPosition, size = wx.Size( 336,79 ), style = wx.DEFAULT_FRAME_STYLE|wx.FRAME_FLOAT_ON_PARENT|wx.TAB_TRAVERSAL )
self.SetSizeHints( wx.DefaultSize, wx.DefaultSize )
self.Centre( wx.BOTH )
# Connect Events
self.Bind( wx.EVT_ACTIVATE, self.Child_activate )
self.Bind( wx.EVT_CLOSE, self.Child_close )
self.Bind( wx.EVT_IDLE, self.Child_idle )
def __del__( self ):
pass
# Virtual event handlers, overide them in your derived class
def Child_activate( self, event ):
event.Skip()
def Child_close( self, event ):
event.Skip()
def Child_idle( self, event ):
event.Skip()
import wx
import pyframe
class Mainframe( pyframe.MyFrame1 ):
def __init__( self, parent ):
pyframe.MyFrame1.__init__( self, parent )
# フレーム位置とサイズの取得
pos = self.GetScreenPosition()
size = self.GetSize()
# 本来フレーム表示されるはずだった位置
print("pos:",pos)
print("size:",size)
# 位置とサイズの設定
self.SetPosition( (100,100) )
self.SetSize( (300,100) )
# フレームのタイトルを取得
print(self.GetTitle())
# Mainframeを親とする子フレームを作る
childflame = Childframe( self ) # 引数1はparentなのでself=Mainframeを親とするChildframe
# フレームを表示する
childflame.Show()
# Mainframeを親とする子フレームを作る
class Childframe( pyframe.MyFrame2 ):
def __init__( self, parent ):
pyframe.MyFrame2.__init__( self, parent )
# 親のクラスオブジェクトを取得
self.parent = parent
# フレームのタイトルを変更
self.SetTitle("僕こども")
self.count=0
# アイドル状態の時常に実行
def Child_idle( self, event ):
self.count += 1
print("idle",self.count)
# フレームを閉じようとした時に発生するイベント
def Child_close( self, event ):
print("Child_close")
# 親のタイトルを変更
self.parent.SetTitle("子が消えた!")
# フレームを閉じる
self.Destroy()
# フレームがアクティブまたは非アクティブになった時に発生するイベント
def Child_activate( self, event ):
print("Child_activate")
app = wx.App( False )
frame = Mainframe( None )
frame.Show( True )
app.MainLoop()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment