python tkinter popup window with selectable text python tkinter popup window with selectable text tkinter tkinter

python tkinter popup window with selectable text


From here, it seems a workaround using Entry in Tkinter is doable. Here is the code:

import Tkinter as Tkroot = 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()

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 editionT.pack()mainloop()

I'm (still) interested in any better solution :)


You can use buttons for copy and paste. First you need to select. In a text widget it is easily done by

selection=nameoftextwidget.get(SEL_FIRST,SEL_LAST)

Then you can use this for copying easily by the use of selection. If you want to copy/paste it in that same text widget, you can use:

nameoftextwidget.insert(END,"\n"+selection)