今天用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()
版权声明:本文为博主原创文章,未经博主允许不得转载。
原文:http://blog.csdn.net/ppppppppp2009/article/details/47708485