在不显示窗口的情况下,通过 tkinter 从剪贴板中复制内容
假设在一个特定的应用程序中,我们需要复制驻留在剪贴板中的内容,可以使用 clipboard_get() 访问剪贴板。
从剪贴板复制文本后,它将驻留在缓存内存中,通过它我们可以调试程序并在框架中显示文本,然后我们可以在剪贴板中看到复制的文本。
首先,我们将创建一个窗口,使用 get 方法来存储源中复制的字符或文本。一旦执行完成,我们就可以使用 Tkinter 中的“withdraw”方法隐藏窗口。它有助于摆脱窗口。
示例
#Import the tkinter library
from tkinter import *
#Create an instance of tkinter canvas by executing it
win = Tk()
win.geometry("600x200")
#Get the data from the clipboard
cliptext = win.clipboard_get()
#Create the label for the clipboard
lab=Label(win, text = cliptext)
lab.pack()
#Keep Running the window
win.mainloop()输出
运行上面的代码片段将复制剪贴板中的内容并将其显示在一个窗口中。

为了避免窗口,我们可以使用“withdraw”方法,
from tkinter import * win = Tk() win.withdraw() number = win.clipboard_get()
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP