質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

Q&A

解決済

1回答

2211閲覧

[wxpython] 子ウインドウから親ウインドウの表示・非表示を操作したい。

yamatail

総合スコア77

Python 3.x

Python 3はPythonプログラミング言語の最新バージョンであり、2008年12月3日にリリースされました。

1グッド

1クリップ

投稿2020/03/12 07:13

編集2020/03/18 08:28

子や孫ウインドウから親画面の表示・非表示を操作したいのですが、どのようにすればいけますでしょうか。

子ウインドウからは非表示には出来ないものなのでしょうか。

もしご存知の方いらっしゃいましたら、ご教授いただければ幸いです。

<開発環境>
windows10 64bit
python3.x

python

1import wx 2 3class GchildFrame(wx.Frame): 4 def __init__(self,parent): 5 wx.Frame.__init__(self,parent,wx.ID_ANY,"Grandchild frame",pos=(200,200)) 6 7 pane2 = wx.Panel(self) 8 self.exitBtn = wx.Button(pane2,label="Hide parent",pos=(10,10)) 9 self.Bind(wx.EVT_BUTTON,self.exit2,self.exitBtn) 10 11 def exit2(self,event): 12 pass # 親ウインドウを非表示にしたい 13 14class ChildFrame(wx.Frame): 15 def __init__(self,parent): 16 wx.Frame.__init__(self,parent,wx.ID_ANY,"child frame",pos=(100,100)) 17 18 pane2 = wx.Panel(self) 19 self.gchildBtn = wx.Button(pane2,label="show grandchild",pos=(10,10)) 20 self.hideBtn = wx.Button(pane2,label="Hide parent",pos=(150,10)) 21 self.Bind(wx.EVT_BUTTON,self.showGchild,self.gchildBtn) 22 self.Bind(wx.EVT_BUTTON,self.showGchild,self.gchildBtn) 23 24 def showGchild(self,event): 25 self.gchildFrame = GchildFrame(self) 26 self.gchildFrame.Show() 27 28 def hideparent(self,event): 29 pass #親ウインドウを非表示にしたい 30 31class MyWindow(wx.Frame): 32 33 def __init__(self, parent, id): 34 wx.Frame.__init__(self,parent,wx.ID_ANY,"main frame") 35 panel = wx.Panel(self) 36 self.showChildBtn = wx.Button(panel,label="show child",pos=(10,10)) 37 self.Bind(wx.EVT_BUTTON,self.showChild,self.showChildBtn) 38 # 子画面を生成する 39 self.childFrame = ChildFrame(self) 40 41 def showChild(self,event): 42 self.childFrame.Show() 43 44if __name__ == '__main__': 45 app = wx.App() 46 frame = MyWindow(parent=None,id=-1) 47 frame.Show() 48 app.MainLoop()
s.k👍を押しています

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答1

0

ベストアンサー

問題箇所
"show grandchild" ボタンのイベントが2重になっていて
"Hide parent" ボタンのイベントが有りません。

python

1# ChildFrame.__init__内 2self.Bind(wx.EVT_BUTTON,self.showGchild,self.gchildBtn) 3self.Bind(wx.EVT_BUTTON,self.showGchild,self.gchildBtn)

diff

1self.Bind(wx.EVT_BUTTON,self.showGchild,self.gchildBtn) 2- self.Bind(wx.EVT_BUTTON,self.showGchild,self.gchildBtn) 3+ self.Bind(wx.EVT_BUTTON,self.hideparent,self.hideBtn)

親ウインドウを非表示にする

同プロセス・同スレッド内からであれば、
通常のウィジェットと同じようにHide()で非表示に出来ます。

python

1def hideparent(self,event): 2 self.GetParent().Hide()

投稿2020/03/21 20:49

teamikl

総合スコア8664

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

yamatail

2020/03/24 02:18

GetParent()という関数があったのですね。 思った通りの動作ができました! ご教授、感謝いたします。
guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問