python学习第二天
2015-08-16 22:42
856 查看
今天用wxpython 实现简单的menu、 button 并为其绑定点击事件和对话框输出,很简单, 但还是需要好好
实现效果如图:
#!/usr/bin/env python # -*- coding: utf-8 -*- # -*- coding: utf-8 -*-才能支持中文 import os import wx class MainWindow(wx.Frame): def __init__(self, parent, title): wx.Frame.__init__(self, parent, title=title,size=(500,500)) # self.control = wx.TextCtrl(self, style = wx.TE_MULTILINE) panel = wx.Panel(self) self.setupMenuBar() self.setupButton(panel) self.Show(True) def setupButton(self, panel): button = wx.Button(panel, label = u"关闭", pos = (150, 60), size = (100, 60)) self.Bind(wx.EVT_BUTTON, self.onAbout, button) def setupMenuBar(self): self.CreateStatusBar() menubar = wx.MenuBar() menufile = wx.Menu() menuabout = menufile.Append(wx.ID_ABORT, '&About', 'about this shit') menuexit = menufile.Append(wx.ID_EXIT, '&Exit', 'end program') menubar.Append(menufile, '&File') self.Bind(wx.EVT_MENU, self.onAbout, menuabout) self.Bind(wx.EVT_MENU, self.onExit, menuexit) self.SetMenuBar(menubar) def onAbout(self, evt): dlg = wx.MessageDialog(self, u'确实要关闭吗?', u'关闭', wx.YES_NO | wx.ICON_QUESTION) if wx.ID_YES == dlg.ShowModal(): self.Close(True) dlg.Destroy() def onExit(self, evt): self.Close(True) def main(): app = wx.App(False) frame = MainWindow(None, 'Small Editor') app.MainLoop() if __name__ == '__main__': main()
实现效果如图:
相关文章推荐
- python中文utf8编码后是占3个字符,unicode汉字为2字节
- python中文utf8编码后是占3个字符,unicode汉字为2字节
- 从底层简析Python程序的执行过程
- Python Web 实战 - 搭建Django环境和初步使用
- 从底层简析Python程序的执行过程
- vijos - P1286座位安排 (DP状态压缩 + 组合数 + python)
- python xpath
- python xpath
- 用Python 爬虫批量下载PDF文档
- splinter python浏览器自动化操作,模拟浏览器的行为
- splinter python浏览器自动化操作,模拟浏览器的行为
- python2+opencv2做图像处理
- Python 之 使用 PIL 库做图像处理
- python验证码识别
- Python 之 使用 PIL 库做图像处理
- python验证码识别
- python对文件的读取操作方式比较
- python修饰器
- 利用Python和goagent代理爬取1024帖子所有图片
- 零基础学python-4.1 python对象的简介和标准类型