[Tutor] Clickable listbox opening .txt files
Alan Gauld
alan.gauld at btinternet.com
Thu Jan 14 19:32:51 EST 2016
On 14/01/16 11:39, Ali Moradi wrote:
> Hi, you said my click event grabs text and doesn't show it. So how do get
> it to show on the Text widget?
Your text widget is calloed text.
So simply insert the text into the widget using
text.insert(END,file)
at the end of your click handler.
> def click(event):
> index = list.curselection()[0]
> file = open(r"C:\Users\deadmarshal\PycharmProjects\ali\1.txt").read()
> list = Listbox(frame1)
> list.insert(1, "Konatiĝu kun Kamila") list.insert(2, "Sinjoro Johano")
> list.insert(3, "Onklino Marta")
> scroll = Scrollbar(frame1, orient=VERTICAL, command=list.yview)
> scroll.grid(row=0, column=2, sticky='ns') list.grid(row=0, column=1)
> list.bind("<ButtonRelease-1>", click)
> text = Text(frame2).grid() root.mainloop()
However one problem is that you are creating your widget and calling
grid() which returns None. You need to split the line into two:
text = Text(frame2)
text.grid()
HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos
More information about the Tutor
mailing list