2006年05月27日 星期六 23:02
我想写一个能够小软件,实现一下功能: 选中一些字符串后,按下快捷键(比如F3),就可以把那些字符串加入到一个文本文档中(比如c:\newwords.txt),我想用来学习英语的,但是不知道如何得到剪贴板中的内容,清高收指教,如果能有人写出这个小程序最好不过,我刚学python。 谢谢大家 -------------- next part -------------- An HTML attachment was scrubbed... URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060527/9217e455/attachment-0001.html
2006年05月28日 星期日 11:11
wxpython in action的18.1讲的就是你想知道的问题,书上有个例子,抄在下面:
import wx
t1_text = """\
The whole contents of this control
will be placed in the system's
clipboard when you click the copy
button below.
"""
t2_text = """\
If the clipboard contains a text
data object then it will be placed
in this control when you click
the paste button below. Try
copying to and pasting from
other applications too!
"""
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="Clipboard",
size=(500,300))
p = wx.Panel(self)
# create the controls
self.t1 = wx.TextCtrl(p, -1, t1_text,
style=wx.TE_MULTILINE|wx.HSCROLL)
self.t2 = wx.TextCtrl(p, -1, t2_text,
style=wx.TE_MULTILINE|wx.HSCROLL)
copy = wx.Button(p, -1, "Copy")
paste = wx.Button(p, -1, "Paste")
# setup the layout with sizers
fgs = wx.FlexGridSizer(2, 2, 5, 5)
fgs.AddGrowableRow(0)
fgs.AddGrowableCol(0)
fgs.AddGrowableCol(1)
fgs.Add(self.t1, 0, wx.EXPAND)
fgs.Add(self.t2, 0, wx.EXPAND)
fgs.Add(copy, 0, wx.EXPAND)
fgs.Add(paste, 0, wx.EXPAND)
border = wx.BoxSizer()
border.Add(fgs, 1, wx.EXPAND|wx.ALL, 5)
p.SetSizer(border)
# Bind events
self.Bind(wx.EVT_BUTTON, self.OnDoCopy, copy)
self.Bind(wx.EVT_BUTTON, self.OnDoPaste, paste)
def OnDoCopy(self, evt):
data = wx.TextDataObject()
data.SetText(self.t1.GetValue())
if wx.TheClipboard.Open():
wx.TheClipboard.SetData(data)
wx.TheClipboard.Close()
else:
wx.MessageBox("Unable to open the clipboard", "Error")
def OnDoPaste(self, evt):
success = False
data = wx.TextDataObject()
if wx.TheClipboard.Open():
success = wx.TheClipboard.GetData(data)
wx.TheClipboard.Close()
if success:
self.t2.SetValue(data.GetText())
else:
wx.MessageBox(
"There is no data in the clipboard in the required format",
"Error")
app = wx.PySimpleApp()
frm = MyFrame()
frm.Show()
app.MainLoop()
在06-5-27,pythonfans <pythonfans at 126.com> 写道:
>
>
> 我想写一个能够小软件,实现一下功能:
>
> 选中一些字符串后,按下快捷键(比如F3),就可以把那些字符串加入到一个文本文档中(比如c:\newwords.txt),我想用来学习英语的,但是不知道如何得到剪贴板中的内容,清高收指教,如果能有人写出这个小程序最好不过,我刚学python。
>
> 谢谢大家
>
>
>
>
>
>
>
>
>
>
> 你 不 想 试 试 今 夏 最 "酷" 的 邮 箱 吗 ?
> 蕴 涵 中 华 传 统 文 化 于 世 界 一 流 科 技 之 中,创 新 Ajax 技 术,126 "D 计 划"火 热 体 验 中 !
> <http://www.126.com/>
>
> _______________________________________________
> python-chinese
> Post: send python-chinese at lists.python.cn
> Subscribe: send subscribe to python-chinese-request at lists.python.cn
> Unsubscribe: send unsubscribe to python-chinese-request at lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.exoweb.net/pipermail/python-chinese/attachments/20060528/60f280b1/attachment.html
2006年05月28日 星期日 21:53
在 06-5-27,pythonfans<pythonfans at 126.com> 写道: > > > 我想写一个能够小软件,实现一下功能: > 选中一些字符串后,按下快捷键(比如F3),就可以把那些字符串加入到一个文本文档中(比如c:\newwords.txt),我想用来学习英语的,但是不知道如何得到剪贴板中的内容,清高收指教,如果能有人写出这个小程序最好不过,我刚学python。 > > 谢谢大家 Windows下可以用Pythonwin里面的win32clipboard模块实现。
Zeuux © 2025
京ICP备05028076号