Python tkinter GUI: which widget to use for having copyable text - python

I am new to designing GUIs in python and have a query:
Is there a way to have a label or any other widget with copyable text. I want to provide help section within GUI which will contain a sample xml to be given as input, I want user to be able to copy that xml.
I don't want that information to go away if user cuts that information, so I am not using a entry widget with pre-filled data.
Is there a way to achieve this?
Thanks!

Use a text widget in disabled state.
There is no insertion cursor in this state, but the text may still be selected and copied (but not modified).

Related

Python GUI: Organizing and Interacting with Displayed Text- Need help to find suitable widget/object

I am quite new to Python and have been writing my first GUI with tkinker with mostly ttk widgets. I have been searching for the better part of a day to figure out how to best go about solving a problem.
My goal: To create a document that will have check boxes next to each entry that when selected to perform an action. I have all the data management figured out. The issue is that I will have a variable number of entrees each with a variable about of text. What i am trying to do is figure out which widget or other object i should use to 1st keep inserted chunks of text aligned with a particular check box and 2nd have the view be scroll-able and locate-able(IE click on words in table of contents and have it bring to view said text from long list of entrees). Would anyone happen to have any suggested library or widgets i should look into to get this working?
I have thought about using many text boxes and linking check boxes to each text box. I cannot however figure out how to make these multitude of text boxes sit in a scroll-able frame that will re-size based on content and still have coordinates to point to that will adjust the view to the proper entry when selected from a table of contents.
A really great tutorial, which takes you through a bunch of widgets can be found here.
http://zetcode.com/gui/pyqt4/
I went through it today, and I already have a working application with QSliders, QFrames, a graph widget and a bunch of controls.

What is the ideal widget in PyQt4 in which we can append text but cannot edit it after the text gets populated?

I am working on a personal project in Python that involves creating a user-interface. For that purpose, I have chosen to go with PyQt4.
As part of the GUI code, I need a widget in which we can append text but the requirement is that it should not allow to be edited. A QtGui.QTextEdit would solve the purpose of appending text but would not satisfy the second requirement. What widget can I use that satisfies both the requirements?
Thanks
Edited by who ?
If you don't want that a user can edit it, I think you just need to set the QTextEdit as readonly with QTextEdit.setReadOnly(True)
If you don't want to edit again from the code, I think you just need to check if the control has some text in it: if no, add the text otherwise return an error (or whatever you need)
You could have two TextEdit's, one that is set to readonly that displays the full text and a smaller one below it for entering text to append to the one above.

How to reliably append text to the end of a text box using wxPython?

Edit2: Solved! I have no idea what changed or why, but now even a RichTextCtrl appends reliably. I left the old message below, despite this.
So I'm writing a GUI in python using wxPython. One of the main elements of this GUI is a textbox.
Features I need:
The ability to reliably append text to the end of the textbox.
Prevent user editing the textbox
Vertical Scroll bar
Features I'd like:
User can select text even when more lines are being appended
Text color can be changed
With that in mind I tried to do use the RichTextCtrl provided by wxPython.
However there appears no way to reliably add text to the end of the text box. The AppendText method is not reliable. If I click a location in the textbox while several lines are being appended this way it is likely one or more of the lines will be inserted where-ever I moved the cursor.
Does anyone have any suggestions on how to reliably append text to a RichTextCtrl? I might be able to clear it and replace all of its text with new text every time I want to append something, but I fear the performance hit from this would be severe. If there is a different text control that would be more appropriate for this please suggest it.
Edit: Using a regular TextCtrl appends reliably. Still no luck with a RichTextCtrl.
AppendText works for me on Windows with wxPython 2.9. If you want to prevent the user from editing, you'll need to use the wx.TE_READ_ONLY style flag. To make a vertical scroll bar appear, add the wx.TE_MULTILINE flag too.
The wxPython demo shows how to change text color. Basically you programmatically select a range and set a style / font for that selection. Getting the ability to select text while appending may not be possible. You would probably have to set up some kind of buffer for the appends and append after the user finishes selecting or keep track of what the user is selecting, append and then reselect.

How to display parsed JSON text

Let me start off by saying that I'm starting this project to get familiar with Python. The project is to parse JSON from Reddit.com every 15 minutes and then display it with Tkinter.
Parsing the JSON text wasn't too difficult, but I'm not sure how display the text. I will need to display two things -- the title of the link and the link -- in a column style view. I was also planning on having two columns side by side to take advantage of the horizontal screen width. I've tried starting out with a Listbox, but that seemed to more be used if you want a selectable list. I just want to display the text and be done with it. Is there a different and more appropriate widget I should be using? I looked into the Entry widget a bit and thought that might be getting closer, but that seemed to only be for storing a single entry.
If you are using a sufficiently modern version of python (2.7, 3....something, I forget) you can use the ttk.Treeview widget which is similar to the listbox but supports multiple columns.
A much simpler choice is to use the text widget. You can insert the text followed by a newline. To line thimgs up in columns just insert a tab, and define an appropriate tab stop.
There are plenty of other options, but those two are arguably the best.
If you haven't dicovered it yet, tkdocs.com has a wealth of information about tkinter.

Place a Button in ListCtrl - wxPython

Is is possible to place a button inside of a ListCtrl item with wxPython? Right now I have a ListCtrl that has data with a file name and size, and I want the user to be able to click a button, to download the file. If this isn't possible, is there a way to display an image in the ListCtrl, and then make it clickable so that I can bind an action to it?
No. You will have to use "UltimateListControl", a generic list implementation that can attach any kind of widget to rows. Check its demo files for examples.
You're probably best off grabbing the trunk code for bugfixes and other changes - I'm not sure how often Andrea updates the main zip on his site
I've yet to use the control, but its demo is very impressive.

Categories