wxpython 給框架增加菜單欄,工具欄和狀態欄


# _*_ coding: utf-8 _*_
__author__ = 'pythonwu'
__date__ = "2018/5/15 16:20"

import wx
from wx.py.shell import ShellFrame
from wx.py.filling import FillingFrame
import wx.py.images as images

class ToolBarFrame(wx.Frame):
def __init__(self,parent,id):
wx.Frame.__init__(self,parent,id,'Toolbars',size = (300,200))
panel = wx.Panel(self)
panel.SetBackgroundColour('White')
statusBar = self.CreateStatusBar() #創建狀態欄
toolBar = self.CreateToolBar() #創建工具欄
toolBar.AddSimpleTool(wx.NewId(),images.getPyBitmap(),"New","Long help for 'New'") #給工具欄增加一個工具
toolBar.Realize() #准備顯示工具欄
menuBar = wx.MenuBar() #創建菜單欄
#創建兩個菜單
menu1 = wx.Menu()
menuBar.Append(menu1,"&File")
menu2 = wx.Menu()
#創建菜單的項目
menu2.Append(wx.NewId(),"&Copy","Copy in status bar")
menu2.Append(wx.NewId(),"C&ut","")
menu2.Append(wx.NewId(),"Paste","")
menu2.AppendSeparator()
menu2.Append(wx.NewId(),"&Options","Display Options")
menuBar.Append(menu2,"&Edit") #在菜單欄上附上菜單
#創建debug菜單及其菜單項
menu3 = wx.Menu()
shell = menu3.Append(-1,"&wxPython sehll","Open wxPython shell frame")
filling = menu3.Append(-1,"&Namespace viewer","OPen namespace viewer frame")
menuBar.Append(menu3,"&Debug")
#設置菜單的事件處理器
self.Bind(wx.EVT_MENU,self.OnShell,shell)
self.Bind(wx.EVT_MENU,self.OnFilling,filling)
self.SetMenuBar(menuBar)
#消息對話框
# dlg = wx.MessageDialog(panel,"Is this the coolest thing ever!","MessageDialog",wx.YES_NO|wx.ICON_QUESTION)
# result = dlg.ShowModal()
# dlg.Destroy()
#文本輸入對話框
# dlg = wx.TextEntryDialog(panel,"Is this the coolest thing ever!","MessageDialog",'Gary')
# if dlg.ShowModal()== wx.ID_OK:
# response = dlg.GetValue()
#從一個列表中選擇
# dlg = wx.SingleChoiceDialog(panel,"Is this the coolest thing ever!","MessageDialog",['1','2','3'])
# if dlg.ShowModal()== wx.ID_OK:
# response = dlg.GetStringSelection()
def OnCloseMe(self,e):
self.Close(True)
def OnCloseWindow(self,e):
self.Destroy()
# OnShell菜單項和OnFilling菜單項處理器
def OnShell(self,e):
frame = ShellFrame(parent=self)
frame.Show()
def OnFilling(self,e):
frame = FillingFrame(parent=self)
frame.Show()

if __name__ == '__main__':
app = wx.PySimpleApp()
frame = ToolBarFrame(parent=None,id= -1)
frame.Show()
app.MainLoop()

"""
ShowModal()方法將對話框以模式框架的方式顯示,這意味着在對話框關
閉之前,應用程序中的別的窗口不能響應用戶事件。ShowModal()方法的返回
值是一個整數,對於wx.MessageDialog,返回值是下面常量之
一: wx.ID_YES, wx.ID_NO, wx.ID_CANCEL, wx.ID_OK。
"""


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM