码迷,mamicode.com
首页 > 编程语言 > 详细

python学习第二天

时间:2015-08-16 23:04:57      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:

今天用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学习第二天

标签:

原文地址:http://blog.csdn.net/ppppppppp2009/article/details/47708485

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!