Py之wxPython:wxPython的简介、安装、使用方法之详细攻略
Py之wxPython:wxPython的簡介、安裝、使用方法之詳細攻略
?
?
目錄
wxPython的簡介
wxPython的安裝
wxPython的使用方法
?
?
?
wxPython的簡介
? ? ? ? ? ? wxPython是Phoenix項目!Phoenix是改進的下一代wxPython,“比以前更好、更強、更快”。這個新的實現主要關注于提高速度、可維護性和可擴展性。就像“經典”的WXPython一樣,菲尼克斯封裝了WxWistGe+C++工具包,并提供了對WxWistGeAPI API的用戶界面部分的訪問,使Python應用程序在Windows、MACS或UNIX系統上具有本地GUI,具有本地的外觀和感覺,并且需要非常少的(如果有的話)特定于平臺的代碼。
?? ? ? ? ? 實用工具wxdocs和wxdemo將使用wxget(如果必要)下載適當的文件,解壓縮它們(如果必要),并啟動相應項的適當版本。(文檔在默認瀏覽器中啟動,演示用python啟動)。
? ? ? ? ? wxPython是Python語言的跨平臺GUI工具箱。使用wxPython,軟件開發人員可以為他們的Python應用程序創建真正的本地用戶界面,這些應用程序在Windows、Mac和Linux或其他類unix系統上很少或沒有修改的情況下運行。
wxPython pypi
wxPython官網
?
wxPython的安裝
pip install wxPython
?
wxPython的使用方法
wx.Frame.SetBackgroundColour(self,'green') ?#給窗口設置背景顏色
?
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 wxclass HelloFrame(wx.Frame):"""A Frame that says Hello World"""def __init__(self, *args, **kw):# ensure the parent's __init__ is calledsuper(HelloFrame, self).__init__(*args, **kw)# create a panel in the framepnl = wx.Panel(self)# and put some text with a larger bold font on itst = wx.StaticText(pnl, label="Hello World!", pos=(25,25))font = st.GetFont()font.PointSize += 10font = font.Bold()st.SetFont(font)# create a menu barself.makeMenuBar()# and a status barself.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 calledwhen the menu item is selected."""# Make a file menu with Hello and Exit itemsfileMenu = wx.Menu()# The "\t..." syntax defines an accelerator key that also triggers# the same eventhelloItem = 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# labelexitItem = fileMenu.Append(wx.ID_EXIT)# Now a help menu for the about itemhelpMenu = 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 frameself.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()?
更多案例應用
Py之wxPython:利用wxPython設計GUI界面(圖片背景+簡單按鈕)
?
?
?
?
?
總結
以上是生活随笔為你收集整理的Py之wxPython:wxPython的简介、安装、使用方法之详细攻略的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 成功解决FileNotFoundErro
- 下一篇: Py之wxPython:利用wxPyth