2009-10-21 8 views

risposta

9

Il modo più semplice è quello di utilizzare un widget di testo disabile con un'altezza di 1 riga:

from Tkinter import * 

master = Tk() 

w = Text(master, height=1, borderwidth=0) 
w.insert(1.0, "Hello, world!") 
w.pack() 

w.configure(state="disabled") 

# if tkinter is 8.5 or above you'll want the selection background 
# to appear like it does when the widget is activated 
# comment this out for older versions of Tkinter 
w.configure(inactiveselectbackground=w.cget("selectbackground")) 

mainloop() 

si potrebbe usare un widget voce in un modo simile.

+1

Per me, 'state =" disabled "' non mi permette nemmeno di selezionare il testo da copiare. Impostandolo su 'state =" readonly "' ha funzionato in realtà. – AneesAhmed777

4

apportate alcune modifiche al codice di cui sopra:

from tkinter import * 

master = Tk() 

w = Text(master, height=1) 
w.insert(1.0, "Hello, world!") 
w.pack() 



# if tkinter is 8.5 or above you'll want the selection background 
# to appear like it does when the widget is activated 
# comment this out for older versions of Tkinter 
w.configure(bg=master.cget('bg'), relief=FLAT) 

w.configure(state="disabled") 

mainloop() 

Il rilievo deve essere piatta in modo per farlo sembrare come una parte normale del display. :)

Problemi correlati