带有可选文本的python tkinter弹出窗口 [英] python tkinter popup window with selectable text

查看:486
本文介绍了带有可选文本的python tkinter弹出窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用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)

提前感谢任何提示

推荐答案

来自

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弹出窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆