pythonの練習でGUIアプリを作成してます。
モジュールはwxpythonを利用して、ファイルダイアログで取得したパスをTextCtrlに表示させたいのですが、どのようにすればよいでしょうか。
python
1import wx 2import os 3 4class MyForm(wx.Frame): 5 # ---------------------------------------------------------------------- 6 def __init__(self): 7 wx.Frame.__init__(self, None, wx.ID_ANY) 8 9 root_panel = wx.Panel(self, wx.ID_ANY) 10 root_layout = wx.BoxSizer(wx.VERTICAL) 11 12 hbox1 = wx.BoxSizer(wx.HORIZONTAL) 13 tc = wx.TextCtrl(root_panel, -1) 14 hbox1.Add(tc, 1, wx.RIGHT, 8) 15 before_bu = wx.Button(root_panel, wx.ID_ANY, "file") 16 before_bu.Bind(wx.EVT_BUTTON, self.onOpenFile) 17 hbox1.Add(before_bu, 0) 18 root_layout.Add(hbox1, 0, wx.EXPAND | wx.LEFT | wx.RIGHT | wx.TOP, 10) 19 root_panel.SetSizer(root_layout) 20 21 # ---------------------------------------------------------------------- 22 23 def onOpenFile(self, event): 24 """ 25 Create and show the Open FileDialog 26 """ 27 dlg = wx.FileDialog( 28 self, message="Choose a file", 29 defaultFile="", 30 style=wx.ID_OPEN 31 ) 32 if dlg.ShowModal() == wx.ID_OK: 33 paths = dlg.GetPaths() 34 35 dlg.Destroy() 36 37 38# ---------------------------------------------------------------------- 39# Run the program 40if __name__ == "__main__": 41 app = wx.App(False) 42 frame = MyForm() 43 frame.Show() 44 app.MainLoop()
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/03/07 13:47
2017/03/07 13:49