Nếu tôi thực thi mã này, nó hoạt động tốt. Nhưng nếu tôi sao chép một cái gì đó bằng bàn phím [Ctrl+C], thì làm thế nào tôi có thể dán văn bản có mặt trên bảng tạm trong bất kỳ hộp nhập hoặc hộp văn bản nào trong Python?
import pyperclip
pyperclip.copy['The text to be copied to the clipboard.']
spam = pyperclip.paste[]
Không gian CDS
2.60917 Huy hiệu vàng33 Huy hiệu bạc36 Huy hiệu đồng17 gold badges33 silver badges36 bronze badges
Đã hỏi ngày 18 tháng 10 năm 2017 lúc 18:56Oct 18, 2017 at 18:56
0
Bạn sẽ muốn vượt qua
import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
3 cùng một nơi bạn sẽ đặt một chuỗi cho phần chèn tiện ích nhập hoặc văn bản của bạn.Hãy xem mã ví dụ này.
Có một nút để sao chép những gì trong trường nhập và một để dán vào trường nhập.
import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
Ngoài ra, bạn chỉ có thể làm ctrl+v: d
Đã trả lời ngày 18 tháng 10 năm 2017 lúc 19:11Oct 18, 2017 at 19:11
Mike - Smtmike - SMTMike - SMT
15.6K4 Huy hiệu vàng34 Huy hiệu bạc68 Huy hiệu Đồng4 gold badges34 silver badges68 bronze badges
Nếu bạn đã sử dụng
import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
4 trong mã của mình và tất cả những gì bạn cần là nội dung trong bảng tạm. Sau đó, import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
4 có một phương pháp được xây dựng để làm điều đó.import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
Để thêm văn bản được sao chép vào mục nhập/văn bản
import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
4, bạn có thể sử dụng biến import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
4:var = tk.StringVar[]
var.set[spam]
Và liên kết biến đó với tiện ích nhập.
box = tk.Entry[root, textvariable = var]
Đã trả lời ngày 19 tháng 10 năm 2017 lúc 17:02Oct 19, 2017 at 17:02
RottencandyrottencandyRottenCandy
6381 Huy hiệu vàng13 Huy hiệu bạc22 Huy hiệu đồng1 gold badge13 silver badges22 bronze badges
Bạn cần xóa dòng sau, vì nó ghi đè lên những gì bạn đã sao chép với bàn phím.
pyperclip.copy['The text to be copied to the clipboard.']
Ví dụ, tôi đã sao chép tiêu đề của bạn, và đây là cách tôi dán nó vào vỏ Python:
>>> import pyperclip
>>> pyperclip.paste[]
'How do I paste the copied text from keyboard in python\n\n'
>>>
Đã trả lời ngày 18 tháng 10 năm 2017 lúc 19:03Oct 18, 2017 at 19:03
Sao chép [] tham số. Phương thức bản sao [] không lấy bất kỳ tham số nào ..pyperclip module. Sao chép [] Giá trị trả về. Phương thức bản sao [] trả về một danh sách mới. .... Ví dụ: Sao chép một danh sách. # Danh sách hỗn hợp my_list = ['Cat', 0, 6.7] ....copy[] method to copy text to the clipboard by: Output: Cảm ơn vì đã đọc. Tôi hy vọng bạn tìm thấy những gì bạn đang tìm kiếm. Mã hóa hạnh phúc! Thủ thuật Python Cách ghi vào một tệp trong Python Với tuyên bố trong Pythonpip install pyperclip
import pyperclip
s1 = "Hello world"
pyperclip.copy[s1]
s2 = pyperclip.paste[]
print[s2]
Hello world
Sự kết luận
Đọc thêm
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Xem thảo luận
Cải thiện bài viết
Lưu bài viết
Đọc is a cross-platform Python module for copy and paste clipboard functions. It works with both Python 2 and 3. This module was created to enable cross-platform copy-pasting in Python which was earlier absent. The
import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
8 module has import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
9 and import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
0 functions that can send text to and receive text from your computer’s clipboard. Sending the output of your program to the clipboard will make it easy to paste it on an email, word processor, or some other software.Bàn luận
import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
0PyperClip là một mô-đun Python đa nền tảng cho các chức năng clipboard sao chép và dán. Nó hoạt động với cả Python 2 và 3. Mô-đun này được tạo ra để cho phép thực hiện sao chép đa nền tảng trong Python mà trước đó không có. Mô -đun
import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
8 có các chức năng import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
9 và import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
0 có thể gửi văn bản và nhận văn bản từ bảng tạm máy tính của bạn. Gửi đầu ra của chương trình của bạn đến bảng tạm sẽ giúp bạn dễ dàng dán nó vào email, trình xử lý văn bản hoặc một số phần mềm khác.Cài đặt pyperclip:
Để sao chép văn bản vào bảng tạm, chuyển một chuỗi đến
import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
1. Để dán văn bản từ bảng tạm, hãy gọi import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
3 và văn bản sẽ được trả về dưới dạng giá trị chuỗi.Mã 1:
import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
8import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
3 import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
4var = tk.StringVar[]
var.set[spam]
2var = tk.StringVar[]
var.set[spam]
3
5import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
6 import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
7import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
1
9import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
6 import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
1var = tk.StringVar[]
var.set[spam]
Để sao chép văn bản vào bảng tạm, chuyển một chuỗi đến
import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
1. Để dán văn bản từ bảng tạm, hãy gọi import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
3 và văn bản sẽ được trả về dưới dạng giá trị chuỗi.Mã 1:
var = tk.StringVar[]
var.set[spam]
9import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
3 import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
4var = tk.StringVar[]
var.set[spam]
2box = tk.Entry[root, textvariable = var]
4import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
5import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
6 import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
7
5import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
6 import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
7import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
import tkinter as tk
from tkinter import ttk
import pyperclip
root = tk.Tk[]
some_entry = tk.Entry[root]
some_entry.pack[]
def update_btn[]:
global some_entry
pyperclip.copy[some_entry.get[]]
def update_btn_2[]:
global some_entry
# for the insert method the 2nd argument is always the string to be
# inserted to the Entry field.
some_entry.insert[tk.END, pyperclip.paste[]]
btn = ttk.Button[root, text="Copy to clipboard", command = update_btn]
btn.pack[]
btn2 = ttk.Button[root, text="Paste current clipboard", command = update_btn_2]
btn2.pack[]
root.mainloop[]
2
9import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
6 import tkinter as tk
root = tk.Tk[]
spam = root.clipboard_get[]
1 Copy function will convert every data type to string.var = tk.StringVar[]
var.set[spam]