基于wxpython實(shí)現(xiàn)的windows GUI程序?qū)嵗?/h1>
更新時(shí)間:2015年05月30日 10:49:53 作者:皮蛋
這篇文章主要介紹了基于wxpython實(shí)現(xiàn)的windows GUI程序,實(shí)例分析了windows GUI程序的相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下
本文實(shí)例講述了基于wxpython實(shí)現(xiàn)的windows GUI程序。分享給大家供大家參考。具體如下:
# using a wx.Frame, wx.MenuBar, wx.Menu, wx.Panel, wx.StaticText, wx.Button,
# and a wx.BoxSizer to show a rudimentary wxPython Windows GUI application
# wxPython package from: http://prdownloads.sourceforge.net/wxpython/
# I downloaded: wxPython2.5-win32-ansi-2.5.3.1-py23.exe
# if you have not already done so install the Python compiler first
# I used Python-2.3.4.exe (the Windows installer package for Python23)
# from http://www.python.org/2.3.4/
# tested with Python23 vegaseat 24jan2005
import wx
class Frame1(wx.Frame):
# create a simple windows frame (sometimes called form)
# pos=(ulcX,ulcY) size=(width,height) in pixels
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(350, 250))
# create a menubar at the top of the user frame
menuBar = wx.MenuBar()
# create a menu ...
menu = wx.Menu()
# ... add an item to the menu
# \tAlt-X creates an accelerator for Exit (Alt + x keys)
# the third parameter is an optional hint that shows up in
# the statusbar when the cursor moves across this menu item
menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit the program")
# bind the menu event to an event handler, share QuitBtn event
self.Bind(wx.EVT_MENU, self.OnQuitButton, id=wx.ID_EXIT)
# put the menu on the menubar
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
# create a status bar at the bottom of the frame
self.CreateStatusBar()
# now create a panel (between menubar and statusbar) ...
panel = wx.Panel(self)
# ... put some controls on the panel
text = wx.StaticText(panel, -1, "Hello World!")
text.SetFont(wx.Font(24, wx.SCRIPT, wx.NORMAL, wx.BOLD))
text.SetSize(text.GetBestSize())
quitBtn = wx.Button(panel, -1, "Quit")
messBtn = wx.Button(panel, -1, "Message")
# bind the button events to event handlers
self.Bind(wx.EVT_BUTTON, self.OnQuitButton, quitBtn)
self.Bind(wx.EVT_BUTTON, self.OnMessButton, messBtn)
# use a sizer to layout the controls, stacked vertically
# with a 10 pixel border around each
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(text, 0, wx.ALL, 10)
sizer.Add(quitBtn, 0, wx.ALL, 10)
sizer.Add(messBtn, 0, wx.ALL, 10)
panel.SetSizer(sizer)
panel.Layout()
def OnQuitButton(self, evt):
# event handler for the Quit button click or Exit menu item
print "See you later alligator! (goes to stdout window)"
wx.Sleep(1) # 1 second to look at message
self.Close()
def OnMessButton(self, evt):
# event handler for the Message button click
self.SetStatusText('101 Different Ways to Spell "Spam"')
class wxPyApp(wx.App):
def OnInit(self):
# set the title too
frame = Frame1(None, "wxPython GUI 2")
self.SetTopWindow(frame)
frame.Show(True)
return True
# get it going ...
app = wxPyApp(redirect=True)
app.MainLoop()
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
-
Python實(shí)現(xiàn)的直接插入排序算法示例
這篇文章主要介紹了Python實(shí)現(xiàn)的直接插入排序算法,結(jié)合實(shí)例形式分析了Python直接插入排序算法的定義與使用相關(guān)操作技巧,代碼備有較為詳盡的注釋便于理解,需要的朋友可以參考下 2018-04-04
-
解決Python pandas plot輸出圖形中顯示中文亂碼問(wèn)題
今天小編就為大家分享一篇解決Python pandas plot輸出圖形中顯示中文亂碼問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧 2018-12-12
-
基于Python的身份證驗(yàn)證識(shí)別和數(shù)據(jù)處理詳解
這篇文章主要介紹了基于Python的身份證驗(yàn)證識(shí)別和數(shù)據(jù)處理,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下 2020-11-11
-
Python如何一行輸入多個(gè)數(shù),并存入列表
這篇文章主要介紹了Python如何一行輸入多個(gè)數(shù),并存入列表,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教 2022-05-05
-
使用python處理題庫(kù)表格并轉(zhuǎn)化為word形式的實(shí)現(xiàn)
這篇文章主要介紹了使用python處理題庫(kù)表格并轉(zhuǎn)化為word形式的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧 2020-04-04
-
python中partial()基礎(chǔ)用法說(shuō)明
這篇文章主要給大家介紹了關(guān)于python中partial()基礎(chǔ)用法的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用python具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧 2018-12-12
最新評(píng)論
本文實(shí)例講述了基于wxpython實(shí)現(xiàn)的windows GUI程序。分享給大家供大家參考。具體如下:
# using a wx.Frame, wx.MenuBar, wx.Menu, wx.Panel, wx.StaticText, wx.Button,
# and a wx.BoxSizer to show a rudimentary wxPython Windows GUI application
# wxPython package from: http://prdownloads.sourceforge.net/wxpython/
# I downloaded: wxPython2.5-win32-ansi-2.5.3.1-py23.exe
# if you have not already done so install the Python compiler first
# I used Python-2.3.4.exe (the Windows installer package for Python23)
# from http://www.python.org/2.3.4/
# tested with Python23 vegaseat 24jan2005
import wx
class Frame1(wx.Frame):
# create a simple windows frame (sometimes called form)
# pos=(ulcX,ulcY) size=(width,height) in pixels
def __init__(self, parent, title):
wx.Frame.__init__(self, parent, -1, title, pos=(150, 150), size=(350, 250))
# create a menubar at the top of the user frame
menuBar = wx.MenuBar()
# create a menu ...
menu = wx.Menu()
# ... add an item to the menu
# \tAlt-X creates an accelerator for Exit (Alt + x keys)
# the third parameter is an optional hint that shows up in
# the statusbar when the cursor moves across this menu item
menu.Append(wx.ID_EXIT, "E&xit\tAlt-X", "Exit the program")
# bind the menu event to an event handler, share QuitBtn event
self.Bind(wx.EVT_MENU, self.OnQuitButton, id=wx.ID_EXIT)
# put the menu on the menubar
menuBar.Append(menu, "&File")
self.SetMenuBar(menuBar)
# create a status bar at the bottom of the frame
self.CreateStatusBar()
# now create a panel (between menubar and statusbar) ...
panel = wx.Panel(self)
# ... put some controls on the panel
text = wx.StaticText(panel, -1, "Hello World!")
text.SetFont(wx.Font(24, wx.SCRIPT, wx.NORMAL, wx.BOLD))
text.SetSize(text.GetBestSize())
quitBtn = wx.Button(panel, -1, "Quit")
messBtn = wx.Button(panel, -1, "Message")
# bind the button events to event handlers
self.Bind(wx.EVT_BUTTON, self.OnQuitButton, quitBtn)
self.Bind(wx.EVT_BUTTON, self.OnMessButton, messBtn)
# use a sizer to layout the controls, stacked vertically
# with a 10 pixel border around each
sizer = wx.BoxSizer(wx.VERTICAL)
sizer.Add(text, 0, wx.ALL, 10)
sizer.Add(quitBtn, 0, wx.ALL, 10)
sizer.Add(messBtn, 0, wx.ALL, 10)
panel.SetSizer(sizer)
panel.Layout()
def OnQuitButton(self, evt):
# event handler for the Quit button click or Exit menu item
print "See you later alligator! (goes to stdout window)"
wx.Sleep(1) # 1 second to look at message
self.Close()
def OnMessButton(self, evt):
# event handler for the Message button click
self.SetStatusText('101 Different Ways to Spell "Spam"')
class wxPyApp(wx.App):
def OnInit(self):
# set the title too
frame = Frame1(None, "wxPython GUI 2")
self.SetTopWindow(frame)
frame.Show(True)
return True
# get it going ...
app = wxPyApp(redirect=True)
app.MainLoop()
希望本文所述對(duì)大家的Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
Python實(shí)現(xiàn)的直接插入排序算法示例
這篇文章主要介紹了Python實(shí)現(xiàn)的直接插入排序算法,結(jié)合實(shí)例形式分析了Python直接插入排序算法的定義與使用相關(guān)操作技巧,代碼備有較為詳盡的注釋便于理解,需要的朋友可以參考下2018-04-04
解決Python pandas plot輸出圖形中顯示中文亂碼問(wèn)題
今天小編就為大家分享一篇解決Python pandas plot輸出圖形中顯示中文亂碼問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-12-12
基于Python的身份證驗(yàn)證識(shí)別和數(shù)據(jù)處理詳解
這篇文章主要介紹了基于Python的身份證驗(yàn)證識(shí)別和數(shù)據(jù)處理,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-11-11
Python如何一行輸入多個(gè)數(shù),并存入列表
這篇文章主要介紹了Python如何一行輸入多個(gè)數(shù),并存入列表,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-05-05
使用python處理題庫(kù)表格并轉(zhuǎn)化為word形式的實(shí)現(xiàn)
這篇文章主要介紹了使用python處理題庫(kù)表格并轉(zhuǎn)化為word形式的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-04-04
python中partial()基礎(chǔ)用法說(shuō)明
這篇文章主要給大家介紹了關(guān)于python中partial()基礎(chǔ)用法的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用python具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起看看吧2018-12-12

