I am trying to find an effective way to create a bar gauge in Tkinter. I've been using labels inside a frame and changing the background color to indicate the level, but this is extremely inefficient as it involves ten if statements, each with ten lines of code, for each gauge. Would anyone be kind enough to point me in the right direction for how to do this?
Thanks in advance.
from the sounds of it you are simple after a progressbar, there are two such widgets in tkinter, one is part of ttk and the other is tix, they function much the same but the styling is different, and both of them can be linked to an IntVar and simply setting the value of the IntVar sets the progressbar.
1) ttk.Progressbar
see here
2) tix.Meter
see here
Related
Is it possible to group buttons that are arbitrarily positionned with PyQt ?
There is the context :
I would like to code a visual programm to control a research system with specific geometry, through Python.
I expect this kind of result :
In this program, the buttons of "buttons group 3" are positionned is a specific geometry that does not fit in a grid. Those buttons are clickable and a click on them change their color.
I would like those buttons to be grouped together, in something like a layout, because it seems to be that it is coherent in order to change positions and sizes of layouts and window if needed.
I'm coding that with PYQT5,... but I cannot figure in PyQt5 how to code this group of buttons with specific geometry ?
Is it possible to group buttons that are arbitrarily positionned with PyQt ?
Thanks in advance for your advice, I feel I'm missing something in PyQt concept.
I am creating a GUI interface that requires user input to conduct a cross-validation assessment on a dataset, and displaying 2 visualisations. My question is how to display these inside the tkinter frame. There is no real nice way of putting the code in, without having to put all of it on here, as all the data is linked to the output of the below confusion matrix (and the program is over 430 lines of code as it is) but essentially, I have a confusion matrix of:
conf_matrix = [[33 8],
[3 47]]
I know you can use ConfusionMatrixDisplay from sklearn.metrics to make the confusion matrix look a lot nicer, with coloured boxes, however, as I said above, really not sure how to put it into a frame inside my tkinter window, as I cannot find anywhere that explains the process of doing so.
I have tried to put it directly onto a canvas, but get an error saying that ConfusionMatrixDisplay doesn't have a set_canvas attribute.
The other visualisation is from matplotlib, however, I imagine that the process is the same to do this as well.
It is important to note too that the frame has used grid() throughout, as there are a lot of buttons, and it was just easier to grid it to make it look nice, so of course the graphs need to be able to be put in a grid if possible!
Any help would be greatly appreciated. Thanks!
I am working with a matplotlib-based routine that returns a figure and, as separate objects, the axes that it contains. Is there any way, that I can display these things and edit them (annotate, change some font sizes, things like that)? "fig.show()" doesn't work, just returns an error. Thanks.
Figures need a canvas to draw on.
Try fig.draw()
I'm trying to plot graph in a scroll area but I've no idea how to change the size of my graphs. Here is an example of what I have:
As you can see, in my ScrollArea (in Red) which as the size I want, I have a graph (well, in reallity I have more graphs and I want to see more then one (at least two) in this area).
So, I want the height of my graph (A) to be smaller and the width of my graph (B) to be expanding. Somine can help me ?
Thanks for your help !
It looks like your plot is inside a layout with the "Hide EMG" button. The widget holding that layout must be resized to fit the scroll area. You'll need to provide a code sample if you want more help than that..
Also consider using pg.MultiPlotWidget, which already provides similar functionality.
Adding to Lukes comment: A PlotWidget, which is probably what we see there, is a QGraphicsView, which is a QWidget. This is layed out using Qt. I'd recommend you to play a bit with Qt Designer to get an intuition on how the layouting works.
Another resource would be: https://doc.qt.io/qt-5/layout.html
For your explicit problem, if you do not want to get into Qt layouting, you could use QWidget.setMinimumHeight and QWidget.setMaximumHeight to confine the widget vertically. For the horizontal part, that totally depends on what you are doing there. If that was a grid layout, I'd refer to e.g.: Expanding only one column in a QGridLayout
So I don't really have any code to show as it's a very large script I have currently. Having said that I will try and add a simple example shortly.
Basically lets say I have two frames in wxpython, each containing a single panel with a matplotlib canvas. Lets call these canvases graph1 and graph2.
So I know how to plot directly into graph1, using standard methods.
I was wondering if there is any way I could change the location of graph1 into that of graph2, i.e. move the plot to the second frame (window).
Basically I am trying to implement a full screen option for the user, which upon clicking a graph will maximise it into the second frame. I am hoping I can do this just by changing the references rather than re-drawing etc. as I want it to keep the original state of the graph when it maximises.