質問編集履歴
1
コード編集
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
子ウインドウから親ウインドウの表示非表示を操作したい。
|
1
|
+
[wxpython] 子ウインドウから親ウインドウの表示・非表示を操作したい。
|
body
CHANGED
@@ -1,38 +1,43 @@
|
|
1
|
-
以下のコードは
|
2
|
-
[親画面から子画面の表示イベントはできますが、子画面の閉じるイベントができない](https://teratail.com/questions/137067)
|
3
|
-
|
1
|
+
子や孫ウインドウから親画面の表示・非表示を操作したいのですが、どのようにすればいけますでしょうか。
|
4
2
|
|
5
|
-
|
3
|
+
子ウインドウからは非表示には出来ないものなのでしょうか。
|
6
4
|
|
5
|
+
もしご存知の方いらっしゃいましたら、ご教授いただければ幸いです。
|
7
6
|
|
7
|
+
<開発環境>
|
8
|
+
windows10 64bit
|
9
|
+
python3.x
|
10
|
+
|
8
11
|
```python
|
9
12
|
import wx
|
10
13
|
|
11
14
|
class GchildFrame(wx.Frame):
|
12
15
|
def __init__(self,parent):
|
13
|
-
wx.Frame.__init__(self,parent,wx.ID_ANY,"Grandchild frame",pos=(
|
16
|
+
wx.Frame.__init__(self,parent,wx.ID_ANY,"Grandchild frame",pos=(200,200))
|
14
17
|
|
15
18
|
pane2 = wx.Panel(self)
|
16
|
-
self.exitBtn = wx.Button(pane2,label="
|
19
|
+
self.exitBtn = wx.Button(pane2,label="Hide parent",pos=(10,10))
|
17
20
|
self.Bind(wx.EVT_BUTTON,self.exit2,self.exitBtn)
|
18
21
|
|
19
22
|
def exit2(self,event):
|
20
23
|
pass # 親ウインドウを非表示にしたい
|
21
|
-
self.Show(False)
|
22
|
-
|
23
24
|
|
24
25
|
class ChildFrame(wx.Frame):
|
25
26
|
def __init__(self,parent):
|
26
27
|
wx.Frame.__init__(self,parent,wx.ID_ANY,"child frame",pos=(100,100))
|
27
28
|
|
28
29
|
pane2 = wx.Panel(self)
|
29
|
-
self.gchildBtn = wx.Button(pane2,label="show
|
30
|
+
self.gchildBtn = wx.Button(pane2,label="show grandchild",pos=(10,10))
|
31
|
+
self.hideBtn = wx.Button(pane2,label="Hide parent",pos=(150,10))
|
30
32
|
self.Bind(wx.EVT_BUTTON,self.showGchild,self.gchildBtn)
|
33
|
+
self.Bind(wx.EVT_BUTTON,self.showGchild,self.gchildBtn)
|
31
34
|
|
32
35
|
def showGchild(self,event):
|
33
|
-
# 画面を閉じるではなく非表示に
|
34
36
|
self.gchildFrame = GchildFrame(self)
|
35
37
|
self.gchildFrame.Show()
|
38
|
+
|
39
|
+
def hideparent(self,event):
|
40
|
+
pass #親ウインドウを非表示にしたい
|
36
41
|
|
37
42
|
class MyWindow(wx.Frame):
|
38
43
|
|
@@ -40,22 +45,15 @@
|
|
40
45
|
wx.Frame.__init__(self,parent,wx.ID_ANY,"main frame")
|
41
46
|
panel = wx.Panel(self)
|
42
47
|
self.showChildBtn = wx.Button(panel,label="show child",pos=(10,10))
|
43
|
-
self.exitBtn = wx.Button(panel,label="exit",pos=(100,10))
|
44
48
|
self.Bind(wx.EVT_BUTTON,self.showChild,self.showChildBtn)
|
45
|
-
self.Bind(wx.EVT_BUTTON,self.exit,self.exitBtn)
|
46
49
|
# 子画面を生成する
|
47
50
|
self.childFrame = ChildFrame(self)
|
48
51
|
|
49
52
|
def showChild(self,event):
|
50
53
|
self.childFrame.Show()
|
51
|
-
return True
|
52
54
|
|
53
|
-
def exit(self, event):
|
54
|
-
self.childFrame.exit2(None)
|
55
|
-
|
56
|
-
|
57
55
|
if __name__ == '__main__':
|
58
|
-
app = wx.
|
56
|
+
app = wx.App()
|
59
57
|
frame = MyWindow(parent=None,id=-1)
|
60
58
|
frame.Show()
|
61
59
|
app.MainLoop()
|