python:wxpython

文書の過去の版を表示しています。


wxPython

wxPython Logo
本家: Welcome to wxPython! | wxPython
ソースコード:
wxWidgets/Phoenix: wxPython's Project Phoenix. A new implementation of wxPython, better, stronger, faster than he was before. (wxPython Phoenix 4系)
wxWidgets/wxPython-Classic: This is the repository for "Classic" wxPython. All new development is happening in the Phoenix project at https://github.com/wxWidgets/Phoenix (wxPython Classic 3系)
リリース:
wxPython · PyPI (wxPython Phoenix 4系)
wxPython - Browse /wxPython at SourceForge.net (wxPython Classic 3系)

 wxPythonは、wxWidgets C++ クラス ライブラリ(クロス プラットフォーム GUIライブラリ)のPython言語向けバインディングである。つまり、PythonからwxWidgetsを利用できるようにしたものである。
 wxPythonを使いPythonでプログラムを記述すると、スクリプト言語でGUIアプリケーションを作成できる。さらに、そのプログラムはLinuxやWindows、Mac OS Xで同じように動作する。(PythonとwxPythonが利用できる様々なプラットフォームで動作する。)

フォルダ構成を以下のようにする。

build_folder
+ wxWidgets
+ wxPython-Classic

wxWidgets をダウンロードする。
GitHub - wxWidgets/wxWidgets: Cross-Platform GUI Library - Report issues here: https://trac.wxwidgets.org/ より clone する。

> git clone --recurse-submodules https://github.com/wxWidgets/wxWidgets.git

–recurse-submodules 無しで clone してしまった場合は以下のコマンドを実行する。

> cd wxWidgets
> git submodule update --init

v3.0.2 タグをチェックアウトする。

> cd wxWidgets
> git checkout -f v3.0.2

wxPython をダウンロードする。

> git clone https://github.com/wxWidgets/wxPython-Classic.git

wxPy-3.0.2.0 タグをチェックアウトする。

> cd wxPython-Classic
> git checkout -f wxPy-3.0.2.0

wxPython をビルドする。
Python 2.7 向けにビルドする場合
予め Microsoft Visual C++ Compiler Pack for Python 2.7 のインストールが必要である。

> cd wxPython-Classic
> "%LOCALAPPDATA%\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat"
Setting environment for using Microsoft Visual Studio 2008 x86 tools.

x32 ビルド

> set CPU=
> python build-wxpython.py

x64 ビルド

> set CPU=X64
> python build-wxpython.py

以下のエラーが発生する場合

error: Microsoft Visual C++ 9.0 is required. Get it from http://aka.ms/vcpython27
ERROR: failed building wxPython.

Download Microsoft Visual C++ Compiler for Python 2.7 from Official Microsoft Download Center より VCForPython27.msi をダウンロードする。
VCForPython27.msi を実行してライセンスに同意してインストールする。
以下のコマンドを実行して Microsoft Visual C++ Compiler Pack for Python 2.7 環境を有効にする。

> "%LOCALAPPDATA%\Programs\Common\Microsoft\Visual C++ for Python\9.0\vcvarsall.bat"
Setting environment for using Microsoft Visual Studio 2008 x86 tools.

以下のエラーが発生する場合

error: Unable to find vcvarsall.bat
ERROR: failed building wxPython.
> set VS90COMNTOOLS="%LOCALAPPDATA%\Programs\Common\Microsoft\Visual C++ for Python\9.0"

Test

> python
Python 2.7.17 (v2.7.17:c2f86d86e6, Oct 19 2019, 21:01:17) [MSC v.1500 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from distutils.msvccompiler import get_build_version
>>> get_build_version()
9.0
>>> from distutils.msvc9compiler import *
>>> find_vcvarsall(9.0)
>>> query_vcvarsall(9.0, "x64")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "c:\python27\Lib\distutils\msvc9compiler.py", line 271, in query_vcvarsall
    raise DistutilsPlatformError("Unable to find vcvarsall.bat")
distutils.errors.DistutilsPlatformError: Unable to find vcvarsall.bat
>>> from setuptools import setup
>>> find_vcvarsall(9.0)
>>> query_vcvarsall(9, "x64")
{u'path': u'C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin\\amd64;C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\WinSDK\\Bin\\x64;C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\WinSDK\\Bin;C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Bin;c:\\devenv\\py27wx\\Scripts;C:\\Python38\\;C:\\Python38\\Scripts\\;C:\\Python27\\Scripts\\;C:\\vstools;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.1\\bin;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.1\\libnvvp;%JDK_HOME%\\bin;C:\\Program Files\\PostgreSQL\\11\\bin;C:\\Tools\\pciutils;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\Android\\android-sdk-windows\\platform-tools;C:\\Program Files (x86)\\Skype\\Phone\\;C:\\Program Files\\PostgreSQL\\9.3\\bin\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Tools\\sakura;C:\\Tools\\WinMerge;C:\\Program Files (x86)\\NVIDIA Corporation\\PhysX\\Common;C:\\Program Files\\NVIDIA Corporation\\NVIDIA NvDLISR;C:\\Program Files\\NVIDIA Corporation\\Nsight Compute 2019.3.0\\;C:\\Program Files\\dotnet\\;C:\\Program Files\\Microsoft SQL Server\\Client SDK\\ODBC\\170\\Tools\\Binn\\;C:\\Program Files\\TortoiseGit\\bin;C:\\Program Files\\TortoiseHg\\;C:\\Program Files (x86)\\QuickTime\\QTSystem\\;C:\\Program Files\\LLVM\\bin;C:\\Program Files\\CMake\\bin;C:\\Program Files\\Git\\cmd;C:\\Program Files (x86)\\IncrediBuild;C:\\DevTools\\gettext-iconv\\gettext-iconv\\bin;C:\\Users\\tomoyan\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\tomoyan\\.dotnet\\tools;%USERPROFILE%\\AppData\\Local\\Microsoft\\WindowsApps',
 
 u'include': u'C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Include;C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\WinSDK\\Include;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.1\\include',
 
 u'lib': u'C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Lib\\amd64;C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\WinSDK\\Lib\\x64;C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Lib;C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\WinSDK\\Lib;C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v10.1\\lib\\x64',
 
 u'libpath': u'C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Lib\\amd64;C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\WinSDK\\Lib\\x64;C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\VC\\Lib;C:\\Users\\tomoyan\\AppData\\Local\\Programs\\Common\\Microsoft\\Visual C++ for Python\\9.0\\WinSDK\\Lib'}
>>> ^Z

setuptoolsimport により monkey patch が当たり Visual C++ for Python が検出される。

[PyWxHelloMain] - UTF-8で保存すること。

#!/usr/bin/env python
# -*- coding: utf-8 -*-
 
import wx
 
# PyWxHelloFrameクラス(wxFrameから派生)
class PyWxHelloFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        wx.Frame.__init__(self, *args, **kwds)
        # Panel生成
        panel = wx.Panel(self, -1)
        # Panelに[閉じる]ボタンを追加
        btnClose = wx.Button(panel, wx.NewId(), u"閉じる")
        # ボタンの位置を設定
        btnClose.SetPosition((50, 35))
        # クリックイベントにイベントハンドラをバインド
        self.Bind(wx.EVT_BUTTON, self.btnClose_Click, btnClose)
 
    # [閉じる]ボタンクリック時
    def btnClose_Click(self, event):
        # 閉じる
        self.Close(True)
 
# PyWxHelloAppクラス(wxAppから派生)
class PyWxHelloApp(wx.App):
    def OnInit(self):
        # PyWxHelloFrameクラスを生成(タイトル、サイズを指定)
        mainFrame = PyWxHelloFrame(None, -1, "Hello wxPython!!", size=(200, 100))
        # トップウインドウとして設定
        self.SetTopWindow(mainFrame)
        # 表示
        mainFrame.Show(True)
        # 正常終了
        return True
 
# メイン処理
def main():
    # PyWxHelloAppクラスを生成
    app = PyWxHelloApp(False)
    # メインループを開始
    app.MainLoop()
 
# スクリプト起動時にmain()を実行
if __name__ == "__main__":
    main()
  • python/wxpython.1580702110.txt.gz
  • 最終更新: 2020/02/03 12:55
  • by ともやん