Embedding a PyQtGraph into a Tkinter GUI - python

I have a Tkinter GUI I've been working on for some time that has a live-plotting feature currently built in matplotlib. However, I'm finding matplotlib to be too slow (it seems to build up a lag over time, as if filling up a buffer of frames of incoming data), so I'm thinking of switching my plotting to PyQtGraph. Can I put this into my Tkinter app?

No, you cannot embed a PyQtGraph Object inside a tkinter application.

Related

Print DataFrames and Plots in Tkinter GUI Application

I found pandastable package which print dataframes in Tkinter applications. I have two questions:
Is it possible to print dataframe in a new window instead in the application window? If yes, how to do it?
How can I add many matplotlib plots to application window? I would like to obtain something similar to Spyder plots bar and also plot them in a new window instead in the application window.

Embedding pyqtgraph in enaml... how?

I'm quite new to pyqt and pyqtgraph so my apology if I'm missing basic things.
I have python program that acquires and plots data, where GUI is implemented by enaml. However the speed of MPL Canvas (matplotlib) was intolerably slow for realtime plotting application, therefore I wish to enhance the performance utilizing pyqtgraph. Immediate conflict seen is that enaml needs to have
from enaml.qt.qt_application import QtApplication
app=QtApplication()
while in order to use pyqtgraph the following seems necessary.
from pyqtgraph.Qt import QtGui, QtCore
app = QtGui.QApplication([])
Can enaml and pyqtgraph coexist or can at least embed pyqtgraph within the enaml thread? If someone can give me a clue it would be a great help. Thanks.
Yes they can exist together. You can create your own declaration and toolkit widgets or use the one from enamlx.
There's an example https://github.com/frmdstryr/enamlx/blob/master/examples/plot_area/plot_area.enaml

Why is the Tkinter render quality much worse on windows?

I have developed a python app with Tkinter on a Mac. It involves forms, and canvas drawings. On the Mac, it looks great. However on my Dell laptop (4K display, and more powerful than my Mac), the Tkinter ui appears very pixelated and certain elements are located slightly differently. What is this problem known as and what can I do to render Tkinter better on Dell Windows 10 or other platforms in general?
Here is a screen shot of the same part of the UI (showing form and canvas drawing)...
Windows(bad)
Mac(normal)
Antialiasing is only enabled for Tkinter canvas object in OSX . You can get the aggDraw lib: http://effbot.org/zone/tkinter-aggdraw.htm as a workaround, but otherwise you will get jagged lines when trying to draw on a canvas. Fonts however should be anti-aliased on all major platforms.
The differences in the display of the same application are due to differences in render engines used by each Operating system.
This is coverd in a Pakt pub ebook called Tkinter GUI Application Development Blueprints
passage regarding this topic available here.
It may be a pain to do but it looks like the most common fix for this is to detect your enviroment and write independent styles using the external option database
more info is available in the documentation here.
Setting your DPI awareness to 1 should resolve your issue
from ctypes import windll
windll.shcore.SetProcessDpiAwareness(1)
Consider the resolution of the MAC as 1366x768 (expected),Suppose you are making your application windows size as 683x384 which is equal to (1366/2 x 768/2).
When the application will be run on a 4k Display it will display the dimensions as 683x384 for the main window but its dimensions on the 4k will be 4k/2.
So what you can do it write a general program with variable dimensions of the screens ,So that it will adjust its window size according to the screen size.
For more details refer to the https://www.tutorialspoint.com/python3/python_gui_programming.htm
Hope this will help.

import a tkinter widget in wxpython application as a panel

I created a analog rpm gauge using the canvas widget of Tkinter and I want to import it in a wx GUI application (as a panel, maybe). Is there any way to do it or I must rewrite this widget in wx?
There is no (simple) way to do that - WxWidgets is an abstraction over different toolkits in different systems, and use different mainloop functions, while Tkinter has its own mainloop - that is to start with.
So making that work would at leas require:
that you'd setup different threads able to run both mainloops in
paralell,
finding a way to get Tkinter to render the widget to an
in memory bitmap
create a custom widget in wx which would render
that bitmap to the screen
and map events on it back to Tkinter, if
it is supposed to respond events
So you are definitely better of writting the widget again.
WxPython has a speed meter widget just use that instead.
import wx.lib.agw.speedmeter
You would have to rewrite the widget in wxPython or find a widget that does the same thing that's already included with wx. Tkinter is a completely different GUI toolkit that draws its own widgets and is based on TCL whereas wxPython is a wrapper around wxWidgets which is based on C++. There is no easy way to embed a widget from Tkinter into wxPython.
As Yoriz mentioned, you might be able to use the speedmeter widget in wxPython. Check out the wxPython demo package as it will show you how to use that widget and most of wxPython's other widgets. Hopefully you can find something that's already included. Otherwise, you may want to take a look at the following page:
http://wiki.wxpython.org/CreatingCustomControls

wxPython, or PyGame canvas within wxPython -> which is faster?

My goal is to capture frames from a webcam as efficiently as possible using OpenCV. At the moment I'm able to capture 30FPS 6408*480 drawing directly onto a wxPython panel using the standard drawing context (BufferedPaintDC), with about 15% CPU usage (older Core Duo processor). What I'm curious is what sort of performance boost (if any) I'll see if I embed a PyGame canvas within a wxPython frame, and draw directly to the PyGame canvas.
What I'm not sure about is whether the bottleneck is the wxPython frame, and if embedding a PyGame canvas will actually do anything. Or does the wxPython frame act simply like a container and has no influence on the PyGame canvas? I'm hoping I'm making sense here.
The other option would be to use PyGame exclusively, however I really like the functionality of the wxPython widgets, so I'd hate to lose that.
Or is there a faster canvas that I can integrate into wxPython that I'm not aware of?
Thoughts? Thanks.
I don't know why you'd want to embed a gaming library into wxPython in the hopes of gaining a performance boost. Personally, I don't think that will happen. You should take a look at the currently supported drawing canvases that wxPython provides instead or explain what you're trying to do. People have done in games in wxPython...
Anyway, the main drawing interfaces for wx today are wx.GCDC / wx.GraphicsContext, cairo, FloatCanvas, or GLCanvas. Of course, there are also wx.DC, wx.PaintDC and the one you found as well.

Categories

Resources