Is the equivalent of ToggleButton exist in PyGtk ?
I would like to have a callback like: True or False.
self.liste = gtk.ComboBox(self.liststore)
self.liste.connect("changed", self.result_list)
With this method, the program can't detect if the user clicks again on the same choice.
Thanks
I don't have any specific advice as I haven't used ComboBox much, but I'm pretty sure that what you want to do is possible.
The GTK tutorial says
ComboBox uses a TreeModel (usually a ListStore) to provide the list
items to display.
The basic ComboBox methods are great for simple things, but for more advanced usage you need to play with things at the TreeModel level yourself. To do that effectively, you need to know how they work; fortunately the docs in the tutorial are pretty good: TreeView widget, but also check out the info in the reference manual.
To make the equivalent of a toggle button you can use 14.4.8. Activatable Toggle Cells
Related
Exactly how do I utilize the various event methods that widgets have? Say I have a comboBox(drop down list) and I want to initiate a function every time someone changes the choice. There is the changeEvent() method in the documentation but It would be great if someone explains to me with a piece of code.
This is a pretty broad question. I recommend checking out the many tutorials on Youtube.com.
However, in your init method, put something like this:
self.ui.charge_codes_combo.currentIndexChanged.connect(self.setup_payments)
In my example, the combo box was placed on a form in Qt Designer. Self.setup_payment is a method triggered by the change in the combo box.
I hope this helps!
I am trying to code a message box that just pops up and says something and has a single button to close it however as I only have a small amount of text in the box the icon/image to the left of it is huge and looks bad. I want to know how to remove it. I am also having trouble making custom message boxes. Tutorials say that this is how you make a custom message box:
box = QMessageBox()
box.setText('text')
box.addButton(QPushButton('Close', self))
box.exec_()
However this just closes my program and returns a 1. My current code uses the about method of QMessageBox():
box = QMessageBox().about(self, 'About', 'This is a test Program')
However this has that large icon in the text window and I can't seem to do anything else to the box as it just stops the program and returns 1 again
I am in desperate need of some decent PyQt documentation. I can't seem to find documentation on much at all unless it is in C++. For instance I cannot seem to find any information of options other than question and about for QmessageBox. So if someone could also show me where some proper documentation lives it would prevent me asking too many questions here
Rather than PyQt documentation, it is better to directly use Qt documentation. You only need to switch your language mindset from Python to C++, there and back. It is not that difficult. :) See e.g. http://doc.qt.io/qt-4.8/qmessagebox.html#addButton or http://doc.qt.io/qt-4.8/qmessagebox.html#about I think this is very detailed documentation, unrivaled by most other frameworks.
Note that there are three overrides of addButton(). From the documentation it seems that you either need to pass two arguments to box.addButton(QPushButton('Close', self), QMessageBox.RejectRole) (you forgot the role!) or better, you use the override which uses standard buttons, then you only pass one argument: box.addButton(QMessageBox.Close).
And one more tip for you: I also find it easier to debug my program with PySide than PyQt because unlike PyQt, PySide catches the exception, prints that to console and keeps running. While PyQt usually just silently crashes leaving you clueless. Most of the time, I am using shims Qt.py https://pypi.python.org/pypi/Qt.py/0.6.9 or qtpy https://pypi.python.org/pypi/QtPy to be able to switch from PyQt to PySide on the fly. It also allows switching between Qt4 and Qt5 bindings easily.
I recently made a simple notepad-like text editor but now I want to implement things like syntax highlighting certain words and automatic indentation as you type. How could I do this dynamically as the user types. So far everything I've done is event-based so I'm guessing I need to have some sort of loop that constantly checks the contents of the textbox as the user is typing? Is tkinter not suited for this? Appreciate it if you steer me in the right direction as to how I can implement this.
Tkinter is quite well suited to this sort of thing. It's possible to make a very smart text editor if you're willing to put in some effort.
This answer shows how to get the text widget to fire an event whenever something in the text widget changes. It's a little complicated, but fairly foolproof.
If you want something simpler, you can simply bind on <Any-KeyRelease> which will fire an event whenever the user releases a key. You can then use the information in the event object to decide what to do. It won't handle the case where you cut and paste with the mouse, for example, and your binding will fire for arrow keys and other non-inserting keys, which is why I recommend the more complicated solution.
This answer shows an example of using a binding on <space> to do do a simple spellcheck, and also shows a fairly simplistic implementation of a toolbar with a "bold" button.
I am looking to know what is the best practice to make a window which the content changes, but without changing the window. Something like using tabs, but with no tabs, controlled with buttons.
What widget should i use to archive what i need?
And if you don't mind the little off-topic, should it be drawn manually or with a GUI designer like glade?
It is meant to be used within python.
If you can use GTK 3.10, take a look at GtkStack and GtkStackSwitcher. If not, use GtkNotebook and set the show_tabs property to False, then build your own buttons.
Is there an on-value-change type of event for data input widgets like Entry, Text, Spinner, Checkbutton, Radiobutton? By on-value-change, I mean the ability to detect when the value of a widget has changed due to keyboard input or cut/delete/paste (and Text edit_undo/edit_redo) activity? I see no such event described in the Tkinter event documentation [1].
Is the proper technique to link Tkinter variables to widget values I want to monitor and use these variables' .trace_variable( 'w', ... ) methods to bind to value changes? This seems like the right approach, but I haven't seen a lot of trace_variable() use in the Tkinter application source code that I've studied ... leading me to be cautious about using this approach.
[1] http://infohost.nmt.edu/tcc/help/pubs/tkinter/events.html
Different widgets call for different solutions. For example, check buttons and radio buttons have a command option, and with an entry widget you can use the built-in validation features.
For all the widgets that can be tied to a variable, doing a variable trace is a common solution. The text widget is one exception since you can't associate it with a variable without a lot of effort.
In the tcl/tk world I associate all my widgets to a single array (tcl's name for a hash map / dictionary) and then put a single trace on the array. Unfortunately tkinter doesn't directly support tcl arrays. However, support is somewhat easy to hack in. For more information see my response to this question: How to run a code whenever a Tkinter widget value changes?