基于wxpython实现的windows GUI程序实例

 更新时间:2015年05月30日 10:49:53   作者:皮蛋  
这篇文章主要介绍了基于wxpython实现的windows GUI程序,实例分析了windows GUI程序的相关实现技巧,需要的朋友可以参考下

本文实例讲述了基于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程序设计有所帮助。

相关文章

  • elasticsearch python 查询的两种方法

    elasticsearch python 查询的两种方法

    这篇文章主要介绍了elasticsearch python 查询的两种方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
    2019-08-08
  • python面向对象之类的继承详解

    python面向对象之类的继承详解

    这篇文章主要介绍了python面向对象之类的继承详解,通过概述定义讲解了类的继承的功能和创建方式,写出了代码实例供参考,以下就是详细内容,需要的朋友可以参考下
    2021-07-07
  • Python读写文件方法总结

    Python读写文件方法总结

    这篇文章主要介绍了Python读写文件方法,实例分析了Python读写文件常用的方法与使用技巧,需要的朋友可以参考下
    2015-06-06
  • Python实现处理apiDoc转swagger的方法详解

    Python实现处理apiDoc转swagger的方法详解

    这篇文章主要为大家详细介绍了Python实现处理apiDoc转swagger的方法,文中的示例代码讲解详细,具有一定的学习价值,感兴趣的小伙伴可以了解一下
    2023-02-02
  • Python实现五子棋联机对战小游戏

    Python实现五子棋联机对战小游戏

    本文主要介绍了通过Python实现简单的支持联机对战的游戏——支持局域网联机对战的五子棋小游戏。废话不多说,快来跟随小编一起学习吧
    2021-12-12
  • Python实现LR1文法的完整实例代码

    Python实现LR1文法的完整实例代码

    这篇文章主要给大家介绍了关于Python实现LR1文法的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2020-10-10
  • Python操作远程服务器 paramiko模块详细介绍

    Python操作远程服务器 paramiko模块详细介绍

    这篇文章主要介绍了Python操作远程服务器 paramiko模块详细介绍,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
    2019-08-08
  • Python如何使用标准库tmpfile库创建临时文件

    Python如何使用标准库tmpfile库创建临时文件

    这篇文章主要介绍了Python如何使用标准库tmpfile库创建临时文件问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2024-02-02
  • Python CSV文件模块的使用案例分析

    Python CSV文件模块的使用案例分析

    这篇文章主要介绍了Python CSV文件模块的使用,结合具体案例形式分析了Python使用csv模块操作csv文件的相关使用技巧与相关注意事项,需要的朋友可以参考下
    2019-12-12
  • Ubuntu 下 vim 搭建python 环境 配置

    Ubuntu 下 vim 搭建python 环境 配置

    这篇文章主要介绍了Ubuntu 下 vim 搭建python环境配置,需要的朋友可以参考下
    2017-06-06

最新评论