国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

使用wxPython獲取系統(tǒng)剪貼板中的數(shù)據(jù)的教程

2020-02-23 01:07:50
字體:
供稿:網(wǎng)友

涉及到開發(fā)桌面程序,尤其是文本處理,剪貼板就很常用,不像 java 中那么煩鎖,wxpython 中訪問剪貼板非常簡單,寥寥幾句足以。

# 取得剪貼板并確保其為打開狀態(tài)text_obj = wx.TextDataObject()wx.TheClipboard.Open()if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open():  # do something...  wx.TheClipboard.Close()

取值:

if wx.TheClipboard.GetData(text_obj):  text = text_obj.GetText()

寫值:

text_obj.SetText(‘要寫入的值')wx.TheClipboard.SetData(text_obj)

下面的例子中,點(diǎn)擊 Copy 會將文本框中的值復(fù)制到剪貼板,點(diǎn)擊 Paste 會將剪貼板中的文本粘貼到文本框中。

"""Get text from and put text on the clipboard."""import wxclass MyFrame(wx.Frame):  def __init__(self):    wx.Frame.__init__(self, None, title='Accessing the clipboard', size=(400, 300))    # Components    self.panel = wx.Panel(self)    self.text = wx.TextCtrl(self.panel, pos=(10, 10), size=(370, 220))    self.copy = wx.Button(self.panel, wx.ID_ANY, label='Copy', pos=(10, 240))    self.paste = wx.Button(self.panel, wx.ID_ANY, label='Paste', pos=(100, 240))    # Event bindings.    self.Bind(wx.EVT_BUTTON, self.OnCopy, self.copy)    self.Bind(wx.EVT_BUTTON, self.OnPaste, self.paste)  def OnCopy(self, event):    text_obj = wx.TextDataObject()    text_obj.SetText(self.text.GetValue())    if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open():      wx.TheClipboard.SetData(text_obj)      wx.TheClipboard.Close()  def OnPaste(self, event):    text_obj = wx.TextDataObject()    if wx.TheClipboard.IsOpened() or wx.TheClipboard.Open():      if wx.TheClipboard.GetData(text_obj):        self.text.SetValue(text_obj.GetText())      wx.TheClipboard.Close()app = wx.App(False)frame = MyFrame()frame.Show(True)app.MainLoop()


發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 大庆市| 双江| 台北县| 泽州县| 铜陵市| 吉林省| 桑日县| 东丽区| 高阳县| 郴州市| 长汀县| 宜州市| 武胜县| 泊头市| 怀柔区| 新闻| 牙克石市| 荆门市| 微山县| 屯留县| 内丘县| 广昌县| 蒲城县| 六枝特区| 图木舒克市| 新乐市| 汝阳县| 庆城县| 虎林市| 黑龙江省| 盐津县| 贡嘎县| 修文县| 大渡口区| 通河县| 东兴市| 克什克腾旗| 庄浪县| 汉川市| 铅山县| 那坡县|