I want to customise the icons (like home, back, forward, pan etc) on the matplotlib toolbar. In this case I am writing a GUI with tkinter with embedded pyplot plot in the widget of the GUI and create the toolbar with NavigationToolbar2Tk.
After searching for a bit I didn't find a clear method to do it. My first approach was to define a child class that inherits everything from NavigationToolbar2Tk and than modify the method where the paths to the icons are located, placing the paths to my custom icons. I was trying to do something like this:
class custom_NavigationToolbar2Tk(NavigationToolbar2Tk):
"""Make a custom toolbar with custom icons"""
def _set_image_for_button(self, button):
"""
Ovveride this method to chose custom icons
"""
path_regular = pathlib.Path(os.path.join(os.path.dirname(__file__), "icons", os.path.basename(button._image_file)))
_set_image_for_button is the name of the method where the variable containing the icons paths path_regular is located. I want to only overide this variable from the parent class, while keeping everything else the same. When in my main code I call custom_NavigationToolbar2Tk it does create the toolbar but it seems to completely ignore the _set_image_for_button method in my code, so the icons remain the old one.
I found a workaround that works, that is I define only the _set_image_for_button method in my code with inside the entire code from NavigationToolbar2Tk._set_image_for_button, only replacing the original expression for the path_regular variable with my expression that gives the location of my custom icons and than I overide the original method like this:
NavigationToolbar2Tk._set_image_for_button = _set_image_for_button
And this does work as expected with old icons replaced by my new icons. But I dont like very much this solution and don't understand why the first approach doesn't work.
I found only 1 analogous question here How do I configure a MatPlotLib Toolbar so that the buttons in the toolbars are ttk buttons instead of old Tk buttons but the solution doesn't work.
Related
I'm currently trying to enable switching the icon theme of an application during runtime.
The problem is that I just cant figure out how to trigger the objects to "refresh" their icons and pick them from the new QIcon.themeSearchPaths().
def change_icon(self):
style = QApplication.style()
if self.standart_icon_theme_active:
QIcon.setThemeSearchPaths([""]) # resetting to the 'default' folder
QIcon.setThemeName(u"")
else:
QIcon.setThemeSearchPaths(["icons/"]) # the folder with my icons
QIcon.setThemeName(u"icons")
for btn in self.bttns:
btn.setIcon(style.standardIcon(getattr(QStyle, btn.objectName()))) # <= im searching for a signal or something to replace this
self.standart_icon_theme_active = not self.standart_icon_theme_active
What I currently have is a little demo Window with a lot of buttons, (which got created with a list of names of icons, so that their name equals the icon they have) in which each icon of each button gets updated when change_icon() gets triggered, and i'm searching for something like a builtin signal which I can emit to let Pyside update each icon on its own, or something in that way.
Any help would be appreciated.
I wanted to ask if it is possible to draw a child window inside a parent window so that it will only be able to move inside the parent window and won't be able to move out of the parent window bounds.
If you mean having actual windows with title bar, menu, status bar etc. inside the parent window then the answer is:
No, Tcl/Tk and by extension Tkinter does not support this with its standard widgets.
There have been efforts in the past to implement widgets which emulate MDI as you can see on the TCL wiki, but most of them are over a decade old. You will probably have to implement it yourself or choose a different GUI toolkit if you really need to implement this kind of UI design.
If you do it yourself, you can use the Frame widget as the subwindow, and use place to put it in the containing window. Or, you can create it as an object on a canvas. You'll have to write all of the code to give the inner window borders and a title bar, and to manage moving it around, iconifying it, etc.
I'm using Gtk to build an application on Linux using Python 3. I'm trying to use a Gtk.HeaderBar. So far it's been working Ok, but it seems that I can't get it to expand it's child widgets. For example:
As you can see above, I've tried putting my Gtk.Entry into the Gtk.HeaderBar, but even with things like Gtk.Entry.set_hexpand(True) it simply refuses to expand. I've even tried putting it inside a Gtk.Box, expanding the Gtk.Box, then adding the Gtk.Entry inside that. Even when I set the Gtk.Entry as a custom title for the Gtk.HeaderBar, this happens:
What's causing this? How can I fix it?
Enabling hexpand only says that you want the widget to be allocated all the remaining space; it does not actually resize your widget. You want the halign property set to GTK_ALIGN_FILL (or whatever it's called in Python) in addition to hexpand.
Check the diagrams on this page for a visual explanation.
You can use Box instead of Headerbar with window.set_titlebar method
I wanted to ask if it is possible to draw a child window inside a parent window so that it will only be able to move inside the parent window and won't be able to move out of the parent window bounds.
If you mean having actual windows with title bar, menu, status bar etc. inside the parent window then the answer is:
No, Tcl/Tk and by extension Tkinter does not support this with its standard widgets.
There have been efforts in the past to implement widgets which emulate MDI as you can see on the TCL wiki, but most of them are over a decade old. You will probably have to implement it yourself or choose a different GUI toolkit if you really need to implement this kind of UI design.
If you do it yourself, you can use the Frame widget as the subwindow, and use place to put it in the containing window. Or, you can create it as an object on a canvas. You'll have to write all of the code to give the inner window borders and a title bar, and to manage moving it around, iconifying it, etc.
I'm writing a class to embed some common configurations of graphs in a wx Notebook tab, but I'm running into a strange issue. When I try to add wx.Panel with the FigureCanvas, instead it floats the figure in another window entirely.
The odd thing is, the graph window resizes when I resize the main window. The figure comes out the correct size, just not in the right window.
My code is here. I can't see what I'm doing wrong, I've embedded matplotlib in wx before, but never in a Notebook. I can get it to embed on a simple GUI by itself just fine, just not in the tabs.
Try:
Make GraphTab a wxPanel rather than a wxFrame
Set all GraphTab to have nb as the parent (currently your first one has self as the parent.
I'm not sure whether this is everything, but it's a start.