python中wx將圖標(biāo)顯示在右下角的腳本代碼
import wx
import images
class DemoTaskBarIcon(wx.TaskBarIcon):
TBMENU_RESTORE = wx.NewId()
TBMENU_CLOSE = wx.NewId()
TBMENU_CHANGE = wx.NewId()
TBMENU_REMOVE = wx.NewId()
def __init__(self, frame):
wx.TaskBarIcon.__init__(self)
self.frame = frame
# Set the image
icon = self.MakeIcon(images.getWXPdemoImage())
self.SetIcon(icon, "wxPython Demo")
self.imgidx = 1
# bind some events
self.Bind(wx.EVT_TASKBAR_LEFT_DCLICK, self.OnTaskBarActivate)
self.Bind(wx.EVT_MENU, self.OnTaskBarActivate, id=self.TBMENU_RESTORE)
self.Bind(wx.EVT_MENU, self.OnTaskBarClose, id=self.TBMENU_CLOSE)
self.Bind(wx.EVT_MENU, self.OnTaskBarChange, id=self.TBMENU_CHANGE)
self.Bind(wx.EVT_MENU, self.OnTaskBarRemove, id=self.TBMENU_REMOVE)
def CreatePopupMenu(self):
"""
This method is called by the base class when it needs to popup
the menu for the default EVT_RIGHT_DOWN event. Just create
the menu how you want it and return it from this function,
the base class takes care of the rest.
"""
menu = wx.Menu()
menu.Append(self.TBMENU_RESTORE, "Restore wxPython Demo")
menu.Append(self.TBMENU_CLOSE, "Close wxPython Demo")
menu.AppendSeparator()
menu.Append(self.TBMENU_CHANGE, "Change the TB Icon")
menu.Append(self.TBMENU_REMOVE, "Remove the TB Icon")
return menu
def MakeIcon(self, img):
"""
The various platforms have different requirements for the
icon size...
"""
if "wxMSW" in wx.PlatformInfo:
img = img.Scale(16, 16)
elif "wxGTK" in wx.PlatformInfo:
img = img.Scale(22, 22)
# wxMac can be any size upto 128x128, so leave the source img alone....
icon = wx.IconFromBitmap(img.ConvertToBitmap() )
return icon
def OnTaskBarActivate(self, evt):
if self.frame.IsIconized():
self.frame.Iconize(False)
if not self.frame.IsShown():
self.frame.Show(True)
self.frame.Raise()
def OnTaskBarClose(self, evt):
self.frame.Close()
def OnTaskBarChange(self, evt):
names = [ "WXPdemo", "Mondrian", "Pencil", "Carrot" ]
name = names[self.imgidx]
getFunc = getattr(images, "get%sImage" % name)
self.imgidx += 1
if self.imgidx >= len(names):
self.imgidx = 0
icon = self.MakeIcon(getFunc())
self.SetIcon(icon, "This is a new icon: " + name)
def OnTaskBarRemove(self, evt):
self.RemoveIcon()
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, -1, "My Frame", size=(300, 300))
panel = wx.Panel(self, -1)
panel.Bind(wx.EVT_MOTION, self.OnMove)
wx.StaticText(panel, -1, "Pos:", pos=(10, 12))
self.posCtrl = wx.TextCtrl(panel, -1, "", pos=(40, 10))
try:
self.tbicon = DemoTaskBarIcon(self)
except:
self.tbicon = None
#wx.CallAfter(self.ShowTip)
#self.Bind(wx.EVT_CLOSE, self.OnCloseWindow)
#self.Bind(wx.EVT_ICONIZE, self.OnIconfiy)
def OnCloseWindow(self, event):
self.dying = True
self.demoPage = None
self.codePage = None
self.mainmenu = None
if self.tbicon is not None:
self.tbicon.Destroy()
self.Destroy()
def OnIconfiy(self, evt):
wx.LogMessage("OnIconfiy: %s" % evt.Iconized())
evt.Skip()
def OnMove(self, event):
pos = event.GetPosition()
self.posCtrl.SetValue("%s, %s" % (pos.x, pos.y))
if __name__ == '__main__':
app = wx.PySimpleApp()
frame = MyFrame()
frame.Show(True)
app.MainLoop()
相關(guān)文章
Python腳本在Appium庫(kù)上對(duì)移動(dòng)應(yīng)用實(shí)現(xiàn)自動(dòng)化測(cè)試
這篇文章主要介紹了使用Python的Appium庫(kù)對(duì)移動(dòng)應(yīng)用實(shí)現(xiàn)自動(dòng)化測(cè)試的教程,屬于Python腳本的一個(gè)自動(dòng)化應(yīng)用,需要的朋友可以參考下2015-04-04Python封裝的類型與作用域的優(yōu)勢(shì)實(shí)例深究
封裝是面向?qū)ο缶幊讨械暮诵母拍?它能夠幫助程序員隱藏類的內(nèi)部細(xì)節(jié),并限制對(duì)類成員的直接訪問,本文將深入探討Python中封裝的機(jī)制,介紹封裝的類型和優(yōu)勢(shì),并提供詳細(xì)的示例展示如何在Python中實(shí)現(xiàn)封裝2023-12-12Python?BeautifulSoup4實(shí)現(xiàn)數(shù)據(jù)解析與提取
Beautiful?Soup是一個(gè)Python的庫(kù),用于解析HTML和XML文檔,提供了方便的數(shù)據(jù)提取和操作功能,下面小編就來和大家詳細(xì)聊聊如何利用BeautifulSoup4實(shí)現(xiàn)數(shù)據(jù)解析與提取吧2023-10-10python實(shí)現(xiàn)m3u8格式轉(zhuǎn)換為mp4視頻格式
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)m3u8格式轉(zhuǎn)換為mp4視頻格式,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-02-02python3從網(wǎng)絡(luò)攝像機(jī)解析mjpeg http流的示例
這篇文章主要介紹了python3從網(wǎng)絡(luò)攝像機(jī)解析mjpeg http流的示例,幫助大家更好的理解和使用python,感興趣的朋友可以了解下2020-11-11