本文实例讲述了基于wxpython实现的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()
希望本文所述对大家的Python程序设计有所帮助。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“基于wxpython实现的windows GUI程序实例”评论...
更新动态
2024年11月25日
2024年11月25日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]