wxPython
Overview:
wxPython is wxPython.
version: - 4.0.1 2018-02-02 - 4.0.0 2018-01-31 license: modified L-GPL OS: Windows(Win32API),MacOS(Cocoa),Linux(GTK+)
Install:
$ pip install -U wxPython wxWidgets Windows build/msw/wx_vc14.sln macOS build/osx/wxcocoa.xcodeproj Ubuntuなど GTK+3の場合 sudo apt-get install libgtk-3-dev ./configure --with-gtk3 --with-gtk=3 --disable-shared make sudo make install
GUI Tool Kit:
wxGlade $ apt-get install libwxgtk2.4 $ apt-get install libwxgtk2.4-python $ tar zxf wxGlade-0.3.3.tar.gz $ cd wxGlade-0.3.3 $ python wxglade.py https://sourceforge.net/projects/wxglade/files/latest/download
Simple Window:
source: | import wx class MainFrame(wx.Frame): def __init__(self, *args, **kwargs): wx.Frame.__init__(self, *args, **kwargs) self.panel = wx.Panel(self, wx.ID_ANY) self.create_menu_bar() self.create_status_bar() def create_menu_bar(self): def create_status_bar(self): class MainApp(wx.App): def OnInit(self): title = "Title" style = wx.DEFAULT_FRAME_STYLE & ~(wx.RESIZE_BORDER | wx.MAXIMIZE_BOX) frame = MainFrame(None, id=wx.ID_ANY, title=title, size=(640, 480), style=style) frame.Show() return True if __name__ == "__main__": app = MainApp() app.MainLoop()
Simple Staus Bar:
source: | # single def create_status_bar(self): sb = self.CreateStatusBar() sb.SetStatusText("text") source: | # split def create_status_bar(self): sb = self.CreateStatusBar() sb.SetFieldsCount(3) sb.SetStatusWidths([-1, -3, -1]) sb.SetStatusText("Left text", 0) sb.SetStatusText("Center text", 1) sb.SetStatusText("Right text", 2)
Simple Menu Bar:
source: | def create_menu_bar(self): # Menu menu = wx.Menu() menu_item = menu.Append(-1, "Event", "StatusBar Text") self.Bind(wx.EVT_MENU, self.OnEvent, menu_item) # MenuBar menu_bar = wx.MenuBar() menu_bar.Append(menu, "Menu") self.SetMenuBar(menu_bar) def OnEvent(self, event): pass
Simple Dialog Box:
source: | wx.MessageBox("Message") source: | dlg = wx.MessageDialog(None, 'Message', 'Title', wx.YES_NO|wx.ICON_QUESTION) result = dlg.ShowModal() if result == wx.ID_YES: pass dlg.Destroy() # ??? wx.OK – OK ボタンを表示(ID: wx.ID_OK) wx.CANCEL – Cancel ボタンを表示(ID: wx.ID_CANCEL) wx.YES_NO – YES, NO ボタンを表示 (ID: wx.ID_YES, wx.ID_NO) wx.YES_DEFAULT – 初期フォーカスを YES ボタンに(デフォルト) wx.NO_DEFAULT – 初期フォーカスを NO ボタンに wx.ICON_INFORMATION – i wx.ICON_QUESTION – ? wx.ICON_EXCLAMATION – ! wx.ICON_ERROR – x wx.ICON_HAND (= wx.ICON_ERROR) wx.STAY_ON_TOP – 最上位にウィンドウを表示する(別アプリ含む) source: | class MyDialog(wx.Dialog): def __init__(self): wx.Dialog.__init__(self, None, -1, 'Title', size=(200,120))