日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

wxpython 安装_wxPython安装与环境配置

發布時間:2024/1/1 python 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 wxpython 安装_wxPython安装与环境配置 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Python語言接觸也有些時間,但平常主要是寫寫完成某些功能命令行的腳本。然后對于圖形界面開發呢,考察了下,python的GUI toolkit主要有:內置的Tkinter庫, pyQt, wxPython等。平時項目中wx用的比較多,那就探索下wxPython吧,正如名字一樣,由開源的C++跨平臺圖形庫wxWidgets,加上python語言綁定而成。結合python語言的簡潔強大與wx的豐富的圖形界面,我們可以快速的開發python GUI程序。

##一、Windows下安裝

Windows下安裝比較簡單:

安裝python(我這里是python2.7.4.msi)

安裝對應版本的wxPython(我的是wxPython2.8-win32-unicode-2.8.12.1-py27)

安裝wxPython的demo和doc(wxPython2.8-win32-docs-demos-2.8.12.1.exe)

裝好后wxpython出現在python包目錄中E:\Python27\Lib\site-packages\wx-2.8-msw-unicode,用python 引入包import wx來寫GUI程序,

差不多了,python demo.py跑跑內帶的demo看看,可以發現wxPython有豐富的ui 元素

C:\Documents and Settings\tanli>python

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win

32

Type "help", "copyright", "credits" or "license" for more information.

>>> import wx

>>> print wx.VERSION

(2, 8, 12, 1, '')

##二、Linux下安裝

Linux下要稍微復雜些:

(1)安裝wxWigets

下載wxGTK-2.8.12.tar.gz解壓后在其目錄下建立bld文件夾,然后運行configure:

../configure --prefix=/home/tanli/local/wxWidget-2.8.12 \

--with-gtk \

--with-gnomeprint \

--with-opengl \

--enable-debug \

--enable-geometry \

--enable-graphics_ctx \

--enable-sound --with-sdl \

--enable-mediactrl \

--enable-display \

--disable-debugreport \

--enable-unicode \

--with-libjpeg=builtin \

--with-libpng=builtin \

--with-libtiff=builtin \

--with-zlib=builtin

(–enable-mediactrl ,可能有個鏈接錯誤,可以去掉)

(2)編譯安裝:

制作一個腳本,內容如下:

make $*

make -C contrib/src/gizmos $*

make -C contrib/src/stc $*

命名為 .make , 放到bld目錄下

然后運行:

$./.make

$./.make install

(3)安裝wxPython:

下載 wxpython: http://downloads.sourceforge.net/wxpython/wxPython-src-2.8.12.1.tar.bz2

解壓,然后在它的wxPython目錄里運行:

python setup.py build_ext --inplace --debug WX_CONFIG=/home/tanli/local/wxWidget-2.8.12/bin/wx-config

WX_CONFIG=/home/tanli/local/wxWidget-2.8.12/bin/wx-config 中的路徑為configure時設置的路徑

(4)設置環境變量:

export LD_LIBRARY_PATH=/home/tanli/local/wxWidget-2.8.12/lib

export PYTHONPATH=/home/tanli/local/wxPython-src-2.8.12.1/wxPython

我將wxPython的源碼文件夾copy到了~/local下,所以第二項是這樣

最后將以上兩項添加道home目錄下的.bashrc中,以后用起來方便點

##三、第一個wxPython程序

寫個圖形版本的hello world吧,這個程序基本可以看出wxPython程序框架和wxWidget是一致的,只不過代碼比C++要簡單的多:

import wx

class MyFrame(wx.Frame):

def __init__(self, parent, title):

wx.Frame.__init__(self, parent, title=title, size=(400,300))

self.CreateStatusBar() # A StatusBar in the bottom of the window

# Setting up the menu.

filemenu= wx.Menu()

# wx.ID_ABOUT and wx.ID_EXIT are standard ids provided by wxWidgets.

menuAbout = filemenu.Append(wx.ID_ABOUT, "&About"," Information about this program")

menuExit = filemenu.Append(wx.ID_EXIT,"E&xit"," Terminate the program")

# Creating the menubar.

menuBar = wx.MenuBar()

menuBar.Append(filemenu,"&File") # Adding the "filemenu" to the MenuBar

self.SetMenuBar(menuBar) # Adding the MenuBar to the Frame content.

# Set events.

self.Bind(wx.EVT_MENU, self.OnAbout, menuAbout)

self.Bind(wx.EVT_MENU, self.OnExit, menuExit)

def OnAbout(self,e):

# A message dialog box with an OK button. wx.OK is a standard ID in wxWidgets.

dlg = wx.MessageDialog( self, "Hello world! ", "wxPython Dialog", wx.OK)

dlg.ShowModal() # Show it

dlg.Destroy() # finally destroy it when finished.

def OnExit(self,e):

self.Close(True) # Close the frame.

app = wx.App(False)

frame = MyFrame(None, "wxPython hello world")

frame.Show(True)

app.MainLoop()

總結

以上是生活随笔為你收集整理的wxpython 安装_wxPython安装与环境配置的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。