0

I have some Tkinter code with a Label object. The user needs to be able to select text from the Label in order to copy the text (and paste into something else). However, it seems Labels aren't selectable? I can't figure out how to enable this... any suggestions?

from Tkinter import *

master = Tk()

label = Label(master, text="Example: foo_bar(1,2,3)")
label.pack()

mainloop()
4
Contributors
4
Replies
20
Views
6 Years
Discussion Span
Last Post by woooee
Featured Replies
  • 1

    Take a look at the following thread in Daniweb https://www.daniweb.com/software-development/python/threads/452441/tkinter-entry-value-problem There are more examples under the "Python GUI Programming" thread at the top of the python page. Read More

0

That sort of works, however when you select the text, it's clear that its a text entry field instead of a label. This is because a thick border appears around the text box when you click on it. Is there any way to not have the border appear when selected?

0

Hi, your code works perfectly fine:

import Tkinter as Tk
root = Tk.Tk()
ent = Tk.Entry(root, state='readonly', readonlybackground='white', fg='black')
var = Tk.StringVar()
var.set('Some text')
ent.config(textvariable=var, relief='flat')
ent.pack()
root.mainloop()

But instead of 'Some text' I would like to put a variable of an entry, to display what the user types, but that you are able to copy paste it! For now my code is:

from Tkinter import *

frame = Tk()

userinput = StringVar()

entry = Entry(frame, textvariable=userinput)

userinput.get()

entry2 = Entry(frame, state="readonly")

entry2.set(userinput)

entry2.pack()
entry.pack()

frame.mainloop()

It displays an error, and I have to figure this out soon, for a school project
Hope you can help :D Thanx

Edited by FredyTek

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.