问题描述
我想使用Tkinter制作弹出窗口.我可以这样做:
I want to make popup window using Tkinter.I can do it so:
import Tkinter
a="some data that use should be able to copy-paste"
tkMessageBox.showwarning("done","message")
但是有一个问题,用户需要能够选择,复制和粘贴显示的文本.这样是不可能的.
But there is one problem that user need to be able to select, copy and paste shown text.It's not possible to do in such way.
有什么方法可以用Tkinter做到吗? (或默认情况下python随附的其他工具)
Are there any ways to do it with Tkinter? (or another tools that is supplied with python by default)
提前感谢任何提示
推荐答案
来自在此,看来在Tkinter中使用Entry
的一种解决方法是可行的.这是代码:
From here, it seems a workaround using Entry
in Tkinter is doable. Here is the code:
import Tkinter as Tk
root = Tk.Tk()
ent = Tk.Entry(root, state='readonly')
var = Tk.StringVar()
var.set('Some text')
ent.config(textvariable=var, relief='flat')
ent.pack()
root.mainloop()
编辑:为回复您的评论,我找到了使用Text
小部件插入多行文本的方法.这是解决方案的草稿:
EDIT: To respond to your comment, I found a way to insert multi-line text, using the Text
widget.Here is a draft of a solution:
from Tkinter import *
root = Tk()
T = Text(root, height=2, width=30, bg='lightgrey', relief='flat')
T.insert(END, "Just a text Widget\nin two lines\n")
T.config(state=DISABLED) # forbid text edition
T.pack()
mainloop()
我(仍然)对任何更好的解决方案感兴趣:)
I'm (still) interested in any better solution :)
这篇关于带有可选文本的python tkinter弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!