Python 允许用户在tkinter gui中复制文本
在这段代码中,当用户输入链接时,会显示链接的简短版本,但用户无法从GUI复制链接。我该如何解决这个问题Python 允许用户在tkinter gui中复制文本,python,python-3.x,url,tkinter,Python,Python 3.x,Url,Tkinter,在这段代码中,当用户输入链接时,会显示链接的简短版本,但用户无法从GUI复制链接。我该如何解决这个问题 import pyshorteners as pr from tkinter import * root = Tk() e = Entry(root, width=50) e.pack() def click(): link = e.get() shortener = pr.Shortener() Short_Link = shortener.tinyurl.sh
import pyshorteners as pr
from tkinter import *
root = Tk()
e = Entry(root, width=50)
e.pack()
def click():
link = e.get()
shortener = pr.Shortener()
Short_Link = shortener.tinyurl.short(link)
Label1 = Label(root, text=Short_Link)
Label1.pack()
Button1 = Button(root, text="Enter link:", command=click)
Button1.pack()
root.mainloop()
不能使用CTRL+C直接从Tkinter标签小部件复制文本 这是一个简单的Tkinter应用程序,用于将标签文本复制到剪贴板:
from tkinter import *
from tkinter.messagebox import showinfo
class CopyLabel(Tk):
def __init__(self, text: str):
super(CopyLabel, self).__init__()
self.title('Copy this Label')
self.label_text = text
self.label = Label(self, text=text)
self.label.pack(pady=10, padx=40)
self.copy_button = Button(self, text='COPY TO CLIPBOARD', command=self.copy)
self.copy_button.pack(pady=5, padx=40)
def copy(self):
self.clipboard_clear()
self.clipboard_append(self.label_text)
self.update()
showinfo(parent=self, message='Copied to clipboad!')
if __name__ == "__main__":
app = CopyLabel('Copy me!')
app.mainloop()
在代码中自动复制短链接,您可以执行以下操作:
import pyshorteners as pr
from tkinter import *
root = Tk()
e = Entry(root, width=50)
e.pack()
def click(master: Tk):
link = e.get()
shortener = pr.Shortener()
Short_Link = shortener.tinyurl.short(link)
master.clipboard_clear()
master.clipboard_append(Short_Link)
master.update()
Label1 = Label(root, text=Short_Link)
Label1.pack()
Button1 = Button(root, text="Enter link:", command=lambda: click(root))
Button1.pack()
root.mainloop()
不能使用CTRL+C直接从Tkinter标签小部件复制文本 这是一个简单的Tkinter应用程序,用于将标签文本复制到剪贴板:
from tkinter import *
from tkinter.messagebox import showinfo
class CopyLabel(Tk):
def __init__(self, text: str):
super(CopyLabel, self).__init__()
self.title('Copy this Label')
self.label_text = text
self.label = Label(self, text=text)
self.label.pack(pady=10, padx=40)
self.copy_button = Button(self, text='COPY TO CLIPBOARD', command=self.copy)
self.copy_button.pack(pady=5, padx=40)
def copy(self):
self.clipboard_clear()
self.clipboard_append(self.label_text)
self.update()
showinfo(parent=self, message='Copied to clipboad!')
if __name__ == "__main__":
app = CopyLabel('Copy me!')
app.mainloop()
在代码中自动复制短链接,您可以执行以下操作:
import pyshorteners as pr
from tkinter import *
root = Tk()
e = Entry(root, width=50)
e.pack()
def click(master: Tk):
link = e.get()
shortener = pr.Shortener()
Short_Link = shortener.tinyurl.short(link)
master.clipboard_clear()
master.clipboard_append(Short_Link)
master.update()
Label1 = Label(root, text=Short_Link)
Label1.pack()
Button1 = Button(root, text="Enter link:", command=lambda: click(root))
Button1.pack()
root.mainloop()
您可以使用一些按钮来复制文本,或者自动复制文本,或者您可以
bind
keyCtrl+C
到窗口。或者您可以在条目中显示它,然后您可以选择文本并使用Ctrl+C
您可以使用一些按钮复制文本,或者自动复制文本,或者您可以绑定键Ctrl+C
到窗口。或者您可以在条目中显示它,然后您可以选择文本并使用Ctrl+C