Python Tkinter : Control/set the (Tab key) widget "visit" order - python

Widget "visit" (tab key) order is determined by the order of widget creation. Is there a simple, pure Python (3.x) way to force the widgets to be visited in a different, user-determined order? If not, is there a simple "Tk" way of doing this? (BTW, This is about about widgets, not notebook tabs).
I couldn't find anything about how to do this while researching the usual tkinter sites, on stackoverflow etc. Have I missed something basic, a widget parameter, universal method, etc.?
Example of why this ability is needed:
The python code (an application/package/class) uses several different widget types and implemented as several files. The definition/creation of all widgets of the same type, e.g. checkboxes, are placed (isolated) inside their own file (e.g. there is a Checkbox file, a Notebook file, a Button File, etc). At initialization this organization causes all occurances of one widget type to be created (and thus tab-ordered) sequentially - and before/after any widgets of any other type.
The resulting widget "visit" order is not (from the users viewpoint) the natural order. How can I force the natural order without resorting to changing the order of widget creation (or doing somethlng as kludgey/artificial as placing every widget in it's own frame and then arranging the frame creation order to match the natural order)?

Related

Is there a list of all QSS properties for QSlider in QT for Python?

I've only just started learning to code and i'm using Python 3. I'm making a GUI in PySide2 and have been struggling with customising a slider object. I've managed to bodge some code together to change the shape and size of various components of the QSlider object, but could really use a full list of editable parameters for each objects' stylesheet ideally. The doc.qt.io site either lists every object with a small portion of the changeable parameters and some limited examples, or there is a list of every single parameter on stylesheets from every single object, but doesn't specify if certain properties are exclusive to objects (and some definitely are).
Is there documentation anywhere that lists each object in QT and its associated stylesheet options? The main reason for me making this post is that i was looking for a way to edit a QSlider's handle when it is in a pressed state but cannot find what the parameter for that would be. I managed to find that mouseover is done with "hover" but not much else.

Kivy; How to id a KV lang width in python code?

When a window-level event (such as a mouse click or a drag-n-drop) occurs in a Kivy application, it gets passed to the entire widget tree. I have multiple widgets of the same class spread across my UI, and need to know which the event occured over. Although I can filter using self.collide(), once I've done that I need to know WHICH widget it is - i.e. is it the top widget in my UI, or the bottom, or what.
I had intended to do this by giving unique names to the "id" value in the kv file for each relevant widget, then run cases in my code based on that. But I was disappointed to find out that "...note that the id will not be available in the widget instance..."
so what's the best practice for giving each widget a unique ID in the kv lang file that can be reference in code? Certainly I could use object properties, but that seems like overkill. Is there some simpler method?
Just give the widgets an identifying attribute or property. If you wanted a string ID, use a StringProperty. It isn't really clear to me that this app structure is the best way to do solve your problem, but it will work fine.

PyQT Qtabwidget add, remove, hide, show certain tab

I am trying to build a GUI which will:
Load a file with parameters which describe certain type of problem.
Based on the parameters of the file, show only certain tab in QTabwidget (of many predefined in Qt Designer .ui)
I plan to make a QTabwidget with, say 10 tabs, but only one should be visible based on the parameters loaded. Enabling certain tab is not an option since it takes to many space and the disabled tabs are grey. I do not want to see disabled tabs.
Removing tab could be an option but the index is not related to a specific tab so I have to take care of the shift in the indices. And furthermore if user loads another file with different parameters, a good tab should be added and the current one removed.
My questions are:
How to do this effectively?
Is it better to use any other type of widget?
In Qt designer, is it possible to define many widgets one over another and then just push the good one in front. If yes, how? And how to edit and change any of them?
If using RemoveTab, how to use pointers on tabs, rather than indices?
I use PyQt4
Use a QStackedWidget, which is exactly the same as a tab-widget, but without the tab-bar (which you don't need).
This widget is available in Qt Designer. The context menu has several commands for adding/removing pages and so forth. Note that the arrow buttons in the top-right corner are just there for convenience: they won't appear in your application.
Pages can be added/removed at runtime with addWidget/removeWidget:
index = self.stack.addWidget(self.page1)
self.stack.removeWidget(self.page1)
You can access the pages using either indexes or widget references.
I see that this thread is kinda old. But I hope this will still help.
You can use the remove() method to "hide" the tab. There's no way to really hide them in pyqt4. when you remove it, it's gone from the ui. But in the back end, the tab object with all your settings still exist. I'm sure you can find a way to improvise it back. Give it a try!

Scroll a group of widgets in Tkinter

I want to make a whole column of various widgets scrollable in a Tkinter GUI, like so:
Tkinter can only attach scrollbars to certain widgets, of which, frames are not included. Making a scollable column is a common practice in interfaces, and there should be a simple solution, but so far, all I have been able to find is this hacky example of a scrollable frame, using a canvas widget. A similar hacky solution was used in a similar stack overflow question.
Is there a commonly accepted way in Tkinter to make a column, or a group of widgets, that is scrollable?
The solution using the canvas is the commonly accepted way to solve this problem. It's really not all that hacky, and the end result can be indistinguishable from having a native scrolling container widget.
If you're making a single column, another option is to use a text widget, and use the widget's ability to embed other widgets. Insert a widget, then insert a newline, insert another widget, etc. You then get the scrolling ability for free. The only thing you need to worry about is configuring the width of the embedded windows, which isn't too hard to do.

gtk logic behind treeviewcolumns needing cell renderers

From what I understand about GTK, if I have a TreeView, I can't just use any widget I want to display information about a column. For text, you need a gtk.CellRendererText. For toggle buttons, a gtk.CellRendererToggle. For anything else, it seems you have to implement yourself, which, from a sample one for buttons that I saw, doesn't look straightforward.
Firstly, is this the case? Is there an easy way to set up whatever widget you want to be used to display some text? If not, then why is it implemented this way? If I were designing GTK i would just create some sort of system where when a row was added and when some data model information changes, user-specified callbacks would be called which would add the appropriate widget or change it, respectively.
To write a custom CellRenderer (copy-pasted from this link!):
Register some new properties that your
renderer needs with the type system
and write your own set_property and
get_property functions to set and get
your new renderer's properties.
Write your own cell_renderer_get_size
function and override the parent
object's function (usually the parent
is of type GtkCellRenderer. Note that
you should honour the standard
properties for padding and cell
alignment of the parent object here.
Write your own cell_renderer_render
function and override the parent
object's function. This function does
the actual rendering.
And there is a good/simple example for pyGTK.
Writing a custom CellRenderer is not too hard, the hardness is that how to write a custom widget. If you have learned how to write a custom widget, then writing a custom CellRenderer is easy.
The logic behind this design is flexibility. A TreeViewColumn indicates how the data (from a TreeModel) should be displayed by a CellRenderer, thus a TreeViewColumn which represents a value of boolean type, can be displayed as a text (CellRendererText) or can be displayed as a check box (CellRendererToggle). e.g. a TreeViewColumn which represents a value of integer type, can be displayed as a text (CellRendererText) or can be displayed as a progress bar (CellRendererProgress) or can be displayed as a spin button (CellRendererSpin) or can be displayed as everything that we want.

Categories