How to display parsed JSON text - python

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.

Related

How to remove borders on Tkinter buttons & frames?

I am currently building a simple app to encrypt files using AES encryption in python but the biggest downside of using Tkinter is the look of the UI. I did some research and found examples of what I want but do not know how to recreate it. (Example)
My problem is that when I replace buttons with images (like the OP of the Reddit post said he did in order to have a decent looking UI) I end up with an ugly bar of grey. (Image of the button)
I also want to remove the same type of bar with frames so if you have the answer for specifically that it would still be appreciated.
Support for for styles and themes has existed in tkinter for some time. A theme being a collection of styles for different widgets.
You can read more about style and themes here.
To the best of my knowledge, the standard widgets to not support rounded corners. All widgets have rectangular shapes.
You might be able to create something like that using a Canvas, but it would be a significant amount of work.
A more relevant point is that it might confuse your users if you don't reproduce the way the standard controls work.
UI elements are standardized for the same reason the controls in a car are; once you know one of them you can use all of them.

Is there a way to modify Gtk.EntryCompletion to limit the number of completions displayed?

I've just begun exploring Gtk in Python after using Tkinter and the complexity is a bit overwhelming. I want to use EntryCompletion but I also want to limit the number of completion strings displayed and I have no idea how to go about this. I know from reading the Gtk documentation for EntryCompletion that it uses CellLayout to modify the TreeView, but I really don't know what to do with that information. Also, I know from passing sufficiently large lists of strings to EntryCompletion that the popup will resize with a scrollbar rather than go off-screen. This is precisely the effect I want, but after a specified number of completion strings.

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.

Build complex layout in a dynamic list/grid

I'm building a simple app with python3 and GTK3.0 looking for the correct element for display a layout like the following image
I need display N items this items are load from a database (can be 1000+) and can change (insert, delete, update, etc.) and each item have a complex layout inside (labels, buttons, etc.)
How I can build a layout with a list/grid that dynamically changes.
I've read about GtkTreeView and GtkCellRenderer but i dont know how and other people recommend use GtkBox but how handle a model and update dynamically like ListView/CursorAdapter in android or ListView/Bindings in C#/WPF.
documentation of GTK 3.0 is really poor and does not explain how to extend a widget. another point that the documentation does not explain or at least I have not seen is how to reuse the same element, how to make good use of the resources (memory) when dealing with lots of elements, for example I created a series of widget in glade and I can not use N times. also not possible to create items that are not windows. everything should be within a window. as I can create a different arbitrary element of a window that can be reused.
please when you point me any of the above points, this has an example code can be C #, Python or C + + but it is important to have an example
I've just create a project called 'sqlite-browser' using python3 and gtk. When you display a large number of records in a database, you can use treeview, and add a pager (limit 100/200 records each page). Maybe this project can help you. And here it is: https://github.com/LiuLang/sqlite-browser
This is screenshot:

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.

Categories