Py之wxPython:wxPython的簡介、安裝、使用方法之詳細(xì)攻略
Py之wxPython:wxPython的簡介、安裝、使用方法之詳細(xì)攻略

目錄
wxPython的簡介
wxPython的安裝
wxPython的使用方法
wxPython的簡介
wxPython是Phoenix項(xiàng)目!Phoenix是改進(jìn)的下一代wxPython,“比以前更好、更強(qiáng)、更快”。這個(gè)新的實(shí)現(xiàn)主要關(guān)注于提高速度、可維護(hù)性和可擴(kuò)展性。就像“經(jīng)典”的WXPython一樣,菲尼克斯封裝了WxWistGe+C++工具包,并提供了對(duì)WxWistGeAPI API的用戶界面部分的訪問,使Python應(yīng)用程序在Windows、MACS或UNIX系統(tǒng)上具有本地GUI,具有本地的外觀和感覺,并且需要非常少的(如果有的話)特定于平臺(tái)的代碼。
實(shí)用工具wxdocs和wxdemo將使用wxget(如果必要)下載適當(dāng)?shù)奈募?,解壓縮它們(如果必要),并啟動(dòng)相應(yīng)項(xiàng)的適當(dāng)版本。(文檔在默認(rèn)瀏覽器中啟動(dòng),演示用python啟動(dòng))。
wxPython是Python語言的跨平臺(tái)GUI工具箱。使用wxPython,軟件開發(fā)人員可以為他們的Python應(yīng)用程序創(chuàng)建真正的本地用戶界面,這些應(yīng)用程序在Windows、Mac和Linux或其他類unix系統(tǒng)上很少或沒有修改的情況下運(yùn)行。
wxPython pypi
wxPython官網(wǎng)
wxPython的安裝
pip install wxPython
wxPython的使用方法
wx.Frame.SetBackgroundColour(self,'green') ?#給窗口設(shè)置背景顏色
1、example 一
# First things, first. Import the wxPython package.
import wx
# Next, create an application object.
app = wx.App()
# Then a frame.
frm = wx.Frame(None, title="Hello World")
# Show it.
frm.Show()
# Start the event loop.
app.MainLoop()
2、example 二
#!/bin/python
"""
Hello World, but with more meat.
"""
import wx
class HelloFrame(wx.Frame):
"""
A Frame that says Hello World
"""
def __init__(self, *args, **kw):
# ensure the parent's __init__ is called
super(HelloFrame, self).__init__(*args, **kw)
# create a panel in the frame
pnl = wx.Panel(self)
# and put some text with a larger bold font on it
st = wx.StaticText(pnl, label="Hello World!", pos=(25,25))
font = st.GetFont()
font.PointSize += 10
font = font.Bold()
st.SetFont(font)
# create a menu bar
self.makeMenuBar()
# and a status bar
self.CreateStatusBar()
self.SetStatusText("Welcome to wxPython!")
def makeMenuBar(self):
"""
A menu bar is composed of menus, which are composed of menu items.
This method builds a set of menus and binds handlers to be called
when the menu item is selected.
"""
# Make a file menu with Hello and Exit items
fileMenu = wx.Menu()
# The "\t..." syntax defines an accelerator key that also triggers
# the same event
helloItem = fileMenu.Append(-1, "&Hello...\tCtrl-H",
"Help string shown in status bar for this menu item")
fileMenu.AppendSeparator()
# When using a stock ID we don't need to specify the menu item's
# label
exitItem = fileMenu.Append(wx.ID_EXIT)
# Now a help menu for the about item
helpMenu = wx.Menu()
aboutItem = helpMenu.Append(wx.ID_ABOUT)
# Make the menu bar and add the two menus to it. The '&' defines
# that the next letter is the "mnemonic" for the menu item. On the
# platforms that support it those letters are underlined and can be
# triggered from the keyboard.
menuBar = wx.MenuBar()
menuBar.Append(fileMenu, "&File")
menuBar.Append(helpMenu, "&Help")
# Give the menu bar to the frame
self.SetMenuBar(menuBar)
# Finally, associate a handler function with the EVT_MENU event for
# each of the menu items. That means that when that menu item is
# activated then the associated handler function will be called.
self.Bind(wx.EVT_MENU, self.OnHello, helloItem)
self.Bind(wx.EVT_MENU, self.OnExit, exitItem)
self.Bind(wx.EVT_MENU, self.OnAbout, aboutItem)
def OnExit(self, event):
"""Close the frame, terminating the application."""
self.Close(True)
def OnHello(self, event):
"""Say hello to the user."""
wx.MessageBox("Hello again from wxPython")
def OnAbout(self, event):
"""Display an About Dialog"""
wx.MessageBox("This is a wxPython Hello World sample",
"About Hello World 2",
wx.OK|wx.ICON_INFORMATION)
if __name__ == '__main__':
# When this module is run (not imported) then create the app, the
# frame, show it, and start the event loop.
app = wx.App()
frm = HelloFrame(None, title='Hello World 2')
frm.Show()
app.MainLoop()
更多案例應(yīng)用
Py之wxPython:利用wxPython設(shè)計(jì)GUI界面(圖片背景+簡單按鈕)
Python
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。
版權(quán)聲明:本文內(nèi)容由網(wǎng)絡(luò)用戶投稿,版權(quán)歸原作者所有,本站不擁有其著作權(quán),亦不承擔(dān)相應(yīng)法律責(zé)任。如果您發(fā)現(xiàn)本站中有涉嫌抄襲或描述失實(shí)的內(nèi)容,請(qǐng)聯(lián)系我們jiasou666@gmail.com 處理,核實(shí)后本網(wǎng)站將在24小時(shí)內(nèi)刪除侵權(quán)內(nèi)容。