本文整理汇总了Python中Tkinter.Tk.selection_get方法的典型用法代码示例。如果您正苦于以下问题:Python Tk.selection_get方法的具体用法?Python Tk.selection_get怎么用?Python Tk.selection_get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Tkinter.Tk
的用法示例。
在下文中一共展示了Tk.selection_get方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: csv_clipboard
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
def csv_clipboard(self):
"""Exports the clipboard contents"""
# TODO : what happens if clipboard contents is a CSV string ?
self.logger.info('Getting clipboard contents')
with open(self.output_dir + '\\' + self.computer_name + '_clipboard.csv', 'wb') as output:
csv_writer = get_csv_writer(output)
write_to_csv(["COMPUTER_NAME", "TYPE", "DATA"], csv_writer)
try:
r = Tk() # Using Tk instead because it supports exotic characters
data = r.selection_get(selection='CLIPBOARD')
r.destroy()
write_to_csv([self.computer_name, 'clipboard', unicode(data)], csv_writer)
except:
r.destroy()
win32clipboard.OpenClipboard()
clip = win32clipboard.EnumClipboardFormats(0)
while clip:
try:
format_name = win32clipboard.GetClipboardFormatName(clip)
except win32api.error:
format_name = "?"
self.logger.info('format ' + unicode(clip) + ' ' + unicode(format_name))
if clip == 15: # 15 seems to be a list of filenames
filenames = win32clipboard.GetClipboardData(clip)
for filename in filenames:
write_to_csv([self.computer_name, 'clipboard', filename], csv_writer)
clip = win32clipboard.EnumClipboardFormats(clip)
win32clipboard.CloseClipboard()
record_sha256_logs(self.output_dir + '\\' + self.computer_name + '_clipboard.csv',
self.output_dir + '\\' + self.computer_name + '_sha256.log')
示例2: get_clipboard
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
def get_clipboard():
"""
Get content of OS clipboard.
"""
if 'xerox' in sys.modules.keys():
print "Returning clipboard content using xerox..."
return xerox.paste()
elif 'pyperclip' in sys.modules.keys():
print "Returning clipboard content using pyperclip..."
return pyperclip.paste()
elif 'gtk' in sys.modules.keys():
print "Returning clipboard content using gtk..."
clipboard = gtk.clipboard_get()
return clipboard.wait_for_text()
elif 'win32clipboard' in sys.modules.keys():
wcb = win32clipboard
wcb.OpenClipboard()
try:
data = wcb.GetClipboardData(wcb.CF_TEXT)
except TypeError as e:
print e
print "No text in clipboard."
wcb.CloseClipboard() # User cannot use clipboard until it is closed.
return data
else:
print "locals.keys() is: ", sys.modules.keys().keys()
print "falling back to Tk..."
r = Tk()
r.withdraw()
result = r.selection_get(selection="CLIPBOARD")
r.destroy()
print "Returning clipboard content using Tkinter..."
return result
示例3: __get_clipboard
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
def __get_clipboard(self):
self.logger.info('Getting clipboard contents')
list_to_csv = [("COMPUTER_NAME", "TYPE", "DATA")]
r = None
try:
r = Tk() # Using Tk instead because it supports exotic characters
data = r.selection_get(selection='CLIPBOARD')
r.destroy()
list_to_csv.append((self.computer_name, 'clipboard', unicode(data)))
except:
if r: # Verify that r exists before calling destroy
r.destroy()
win32clipboard.OpenClipboard()
clip = win32clipboard.EnumClipboardFormats(0)
while clip:
try:
format_name = win32clipboard.GetClipboardFormatName(clip)
except win32api.error:
format_name = "?"
self.logger.info('format ' + unicode(clip) + ' ' + unicode(format_name))
if clip == 15: # 15 seems to be a list of filenames
filenames = win32clipboard.GetClipboardData(clip)
for filename in filenames:
list_to_csv.append((self.computer_name, 'clipboard', filename))
clip = win32clipboard.EnumClipboardFormats(clip)
win32clipboard.CloseClipboard()
return list_to_csv
示例4: csv_clipboard
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
def csv_clipboard(self):
''' Exports the clipboard contents '''
# TODO check if it is the same for older windows
self.logger.info('Getting clipboard contents')
with open(self.output_dir + '\\' + self.computer_name + '_clipboard.csv', 'wb') as output:
csv_writer = get_csv_writer(output)
#output.write('"Computer Name"|"Type"|Data"\n')
try:
r = Tk() # Using Tk instead because it supports exotic characters
data = r.selection_get(selection='CLIPBOARD')
r.destroy()
#data = win32clipboard.GetClipboardData().decode('utf_8')
write_to_csv([self.computer_name, 'String data in clipboard', unicode(data)], csv_writer)
except:
r.destroy()
win32clipboard.OpenClipboard()
clip = win32clipboard.EnumClipboardFormats(0)
while clip:
try: format_name = win32clipboard.GetClipboardFormatName(clip)
except win32api.error: format_name = "?"
self.logger.info('format ' + unicode(clip) + ' ' + unicode(format_name))
if clip == 15: # 15 seems to be a list of filenames
filenames = win32clipboard.GetClipboardData(clip)
for filename in filenames:
write_to_csv([self.computer_name, 'List of files in clipboard', filename], csv_writer)
clip = win32clipboard.EnumClipboardFormats(clip)
win32clipboard.CloseClipboard()
示例5: getFromClipboard
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
def getFromClipboard(self):
t = Tk()
t.withdraw()
stuff = t.selection_get(selection="CLIPBOARD")
# for when we have the clipboard figured out
# r.clipboard_clear()
# r.clipboard_append('i can has clipboardz?')
t.destroy()
return stuff
示例6: copy_to_clipboard
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
def copy_to_clipboard(self, text):
from Tkinter import Tk
r = Tk()
r.withdraw()
r.clipboard_clear()
r.clipboard_append(text.strip())
r.destroy()
r = Tk()
result = r.selection_get(selection = "CLIPBOARD")
#logger.debug('tried to copy %s to clipboard, got %s' % (text, result))
r.destroy()
示例7: getClip
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
def getClip():
# gets the operating system
if os == 'darwin':
try:
p = subprocess.Popen(['pbpaste'], stdout=subprocess.PIPE)
buffy = p.stdout.read()
return buffy
except OSError:
print 'Xcode is not installed'
elif os == 'linux2':
try:
p = subprocess.Popen(['xsel --clipboard --output'], stdout=subprocess.PIPE)
buffy = p.stdout.read()
return buffy
except OSError:
print 'xsel must be installed'
elif os == 'win32':
p = Tk()
buffy = p.selection_get(selection='CLIPBOARD')
return buffy
示例8: get_clipboard
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
def get_clipboard():
"""Get content of OS clipboard.
This function tries a range of modules and methods to find a suitable way to get the clipboard content.
Example:
>>> get_clipboard()
"hello there"
"""
if 'xerox' in sys.modules.keys():
print("Returning clipboard content using xerox...")
return xerox.paste()
elif 'pyperclip' in sys.modules.keys():
print("Returning clipboard content using pyperclip...")
return pyperclip.paste()
elif 'gtk' in sys.modules.keys():
print("Returning clipboard content using gtk...")
clipboard = gtk.clipboard_get()
return clipboard.wait_for_text()
elif 'win32clipboard' in sys.modules.keys():
wcb = win32clipboard
wcb.OpenClipboard()
try:
data = wcb.GetClipboardData(wcb.CF_TEXT)
except TypeError as err:
print(err)
print("No text in clipboard.")
else:
wcb.CloseClipboard() # User cannot use clipboard until it is closed.
return data
else:
print("locals.keys() is: ", sys.modules.keys().keys())
print("falling back to Tk...")
tkroot = Tk()
tkroot.withdraw()
result = tkroot.selection_get(selection="CLIPBOARD")
tkroot.destroy()
print("Returning clipboard content using Tkinter...")
return result
示例9: paste
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
def paste(**kwargs):
"""Returns system clipboard contents."""
window = Tk()
window.withdraw()
d = window.selection_get(selection = 'CLIPBOARD')
return d
示例10: Tk
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
from Tkinter import Tk
import urllib2
import re
import json
# set to 1 for debugging
debug = 0
r = Tk()
r.withdraw()
try:
url = r.selection_get(selection = "CLIPBOARD")
r.update_idletasks()
r.destroy()
except BaseException as e:
url = "http://video.toggle.sg/en/series/fighting-spiders-s1/ep1/275423"
# sample (m3u8 and mp4) links
#url = "http://video.toggle.sg/en/series/sabo/ep4/326841"
# sample wvm link
#url = "http://video.toggle.sg/en/series/marvel-s-agents-of-s-h-i-e-l-d-yr-2/ep6/327671"
print "\n[i] Given Toggle URL = %s" % (url)
urlsplit = url.split('/')
mediaID = urlsplit[-1]
if (debug):
print "[*] Obtained mediaID = %s" % (mediaID)
print "[i] Performing HTTP GET request on Toggle URL ..."
urlresp = urllib2.urlopen(url).read()
示例11: addKeyPress
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
#.........这里部分代码省略.........
else:
self.string = self.string[0:self.start] + self.string[self.end:]
self.cursor = self.end = self.start
elif keyCode == K_DELETE:
if self.start == self.end:
self.string = self.string[0:self.start] + self.string[self.end + 1:]
else:
self.string = self.string[0:self.start] + self.string[self.end:]
self.cursor = self.end = self.start
elif keyCode == K_RIGHT:
if keyMods & KMOD_SHIFT != 0:
if self.start == self.end:
self.end += 1
if self.end > len(self.string):
self.end = len(self.string)
self.cursor = self.end
else:
if self.cursor == self.start:
self.start += 1
self.cursor = self.start
else:
self.end += 1
if self.end > len(self.string):
self.end = len(self.string)
self.cursor = self.end
else:
if self.start == self.end:
self.start += 1
if self.start > len(self.string):
self.start = len(self.string)
self.cursor = self.end = self.start
else:
self.cursor = self.start = self.end
elif keyCode == K_LEFT:
if keyMods & KMOD_SHIFT != 0:
if self.start == self.end:
self.start -= 1
if (self.start < 0):
self.start = 0
self.cursor = self.start
else:
if self.cursor == self.start:
self.start -= 1
if (self.start < 0):
self.start = 0
self.cursor = self.start
else:
self.start += 1
self.cursor = self.end
else:
if self.start == self.end:
self.start -= 1
if (self.start < 0):
self.start = 0
self.cursor = self.end = self.start
else:
self.cursor = self.end = self.start
elif keyCode == K_HOME:
if keyMods & KMOD_SHIFT != 0:
self.start = 0
else:
self.cursor = self.end = self.start = 0
elif keyCode == K_END:
if keyMods & KMOD_SHIFT != 0:
self.end = len(self.string)
else:
self.cursor = self.start = self.end = len(self.string)
elif keyCode == K_c and (keyMods & KMOD_CTRL != 0):
tk = Tk()
tk.withdraw()
tk.clipboard_clear()
tk.clipboard_append(self.string[self.start:self.end])
tk.destroy()
elif keyCode == K_v and (keyMods & KMOD_CTRL != 0):
tk = Tk()
tk.withdraw()
clipboard = tk.selection_get(selection = "CLIPBOARD")
tk.destroy()
self.string = self.string[:self.start] + clipboard + self.string[self.end:]
self.cursor = self.start = self.end + len(clipboard)
elif keyCode == K_x and (keyMods & KMOD_CTRL != 0):
tk = Tk()
tk.withdraw()
tk.clipboard_clear()
tk.clipboard_append(self.string[self.start:self.end])
tk.destroy()
self.string = self.string[:self.start] + self.string[self.end:]
elif keyCode == K_a and (keyMods & KMOD_CTRL != 0):
self.start = 0
self.cursor = self.end = len(self.string)
示例12: Tk
# 需要导入模块: from Tkinter import Tk [as 别名]
# 或者: from Tkinter.Tk import selection_get [as 别名]
from Tkinter import Tk
import re
r = Tk()
r.withdraw()
result = r.selection_get(selection = "CLIPBOARD")
if re.match("Rarity:", result):
print result
else:
print "None"
r.destroy()