python - checkbox in new window update fails and stays false - user-interface

import matplotlib
from tkinter import *
matplotlib.use("TkAgg")
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2TkAgg
import tkinter as tk
from tkinter import ttk
import numpy as np
import matplotlib.animation as animation
from matplotlib import style
from matplotlib import pyplot as plt
from scipy.misc import *
import webbrowser
import subprocess
import csv
import matplotlib.ticker as mticker
import matplotlib.dates as mdates
from os import startfile
LARGE_FONT = ("Times", 11, "bold italic")
NORM_FONT = ("Helvetica", 9)
SMALL_FONT = ("Helvetica",7)
HELP_FONT=("Times", 9 , "bold")
class PAL3_guide(tk.Tk):
def __init__(self,*args, **kwargs):
tk.Tk.__init__(self, *args, **kwargs)
container = tk.Frame(self)
container.pack(side="top", fill="both", expand = True)
container.grid_rowconfigure(0, weight=1)
container.grid_columnconfigure(0, weight=1)
self.frames = {}
for F in (StartPage,Tut01):
frame = F(container, self)
self.frames[F] = frame
frame.grid(row=0, column=0, sticky="nsew")
self.show_frame(StartPage)
def show_frame(self, cont):
frame=self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self,parent, controller):
tk.Frame.__init__(self,parent, background="white")
button_PAL = ttk.Button(self, text="Setup Guide", command=lambda:controller.show_frame(Tut01))
button_PAL.pack()
class Tut01(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
var=BooleanVar()
label = tk.Label(self, text="Guide", font=LARGE_FONT)
label.pack(pady=10, padx=10)
label = tk.Label(self, text="Check the methods to accomplish", font=NORM_FONT)
label.pack(pady=10, padx=10)
c1 = Checkbutton(self, state=ACTIVE).pack()
c1Label = tk.Label(self, text="digestion1",font=SMALL_FONT).pack()
c2 = Checkbutton(self, state=ACTIVE).pack()
c2Label = tk.Label(self, text="digestion2",font=SMALL_FONT).pack()
c3 = Checkbutton(self, text="enrichment",state=ACTIVE, variable=var, command=lambda:onClick()).pack()
def onClick():
var.get()
if var == True:
print("hi")
else:
print("hiww")
app = PAL3_guide()
app.geometry("1280x920")
app.mainloop()
Please check last code lines around the c3 checkbox.
I dont get why my boolean variable var is not getting updated by clicking the checkbox on the 2nd page. By clicking the checkbox (c3) the GUI should act differently. However as mentioned above it is not getting updated.. and stays False. I feel it keeps the value from start and does not get changed. Thanks for help ..
EDIT:
Above the if statement missed the var.get() and I could make it work in smaller setup.. however, in the real tool I am calling a plt.figure() in the beginning since it included and anmiate function, If I erase this call, everything works like it should, might be that this figure calling forces the checkbutton to have the first onvalue ?

I would change var, to be self.var and set the off and on values explicitly:
offvalue=
The value corresponding to a non-checked button. The default is 0. (offValue/Value)
onvalue=
The value corresponding to a checked button. The default is 1. (onValue/Value)
c3 = Checkbutton(self, text="enrichment",state=ACTIVE,
variable=self.var, command=onClick,
onvalue=True, offvalue=False)
c3.pack()
command= does not take a function call, just a function.
You would have to write either
command=lambda: print(self.var.get())
OR:
def printVar():
print(self.var.get())
THEN:
..., command=printVar, ...
NOTICE the abscence of the paranthesis!
You are supposed to be settting command to a function.
When you use parenthesis, you CALL the function, you DO NOT want that here.

Related

window.read doesn't return events after creating any window in the matplotlib' toolbar

The code is based on: https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Matplotlib_Embedded_Toolbar.py
One custom button is added to the toolbar and if we call, ex. sg.popup from callback function for this button main loop become broken - no events are returned from any button (Plot and Exit in the example).
import PySimpleGUI as sg
import numpy as np
import os
import sys
import matplotlib.backends
import base64
"""
Embedding the Matplotlib toolbar into your application
Based on:
https://github.com/PySimpleGUI/PySimpleGUI/blob/master/DemoPrograms/Demo_Matplotlib_Embedded_Toolbar.py
"""
# ------------------------------- This is to include a matplotlib figure in a Tkinter canvas
import matplotlib.pyplot as plt
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg, NavigationToolbar2Tk
if os.path.isfile("axsminmax.png") == False:
toolbarpng1 = b'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAABmJLR0QA/wD/AP+gvaeTAAABsklEQVRYhe3Xz2oUQRAG8F8mvoH4CuJbeDagQvBoLtldl+BJIko04j98BiX+IycPXox61zyFkKsevedkxkPXkHHipHd2nQ2KHxTM1lbX9011d/U0s2GE4Yw5psYtlGF3502+GcQ/wsoQNBfcDsLX2MVnPAvfRt/k4yDaRoFPYUX4Sqx0SXiqo4CveIyHOKj5D7CKb/jeMedMqCowNYo/JOTvFdB1DTTxRlp4/xZWcKGHvMtYywXdlEr6JBNX4BreY0c6E3Lr6X7kftAWUPX2bSxmyD9G7F5YiQ8ZEQvYahNRb6+5NxlFbL2ca+EbZMYWeFEXsRAJt6RDZdevHa7C24ghlf0czjZi9vAFl+P3GFdaRJyXqnx90j4w6VYrW57bsF89bMSAl/JTMNQ+BauZsYU0zSXWm39OKqKQFlxzEe5IU9qGRYcn5hHypohHxyQSREO8CxtkyElb+1jyCgNczAVNgSVc7SHvyWIsdcQTw/8PkrkLWJK20+8Oq0Lavpf6FHAad/CqMbbAc9zDmY45O+OGoxeTp+Hb7Ju8QvXtUL+a9X4ramLd4eV0bm/exChsavwEAXVwI8ngt8MAAAAASUVORK5CYII='
with open("axsminmax.png", "wb") as fh:
fh.write(base64.decodebytes(toolbarpng1))
def draw_figure_w_toolbar(canvas, fig, canvas_toolbar):
if canvas.children:
for child in canvas.winfo_children():
child.destroy()
if canvas_toolbar.children:
for child in canvas_toolbar.winfo_children():
child.destroy()
figure_canvas_agg = FigureCanvasTkAgg(fig, master=canvas)
figure_canvas_agg.draw()
toolbar = Toolbar(figure_canvas_agg, canvas_toolbar)
toolbar.update()
figure_canvas_agg.get_tk_widget().pack(side='right', fill='both', expand=1)
def get_res_file_path(fname):
if hasattr(sys, "_MEIPASS"):
fpath = os.path.join(sys._MEIPASS, fname)
else:
basedir = os.path.abspath(os.getcwd())
fpath = basedir+'/'+fname
return fpath
def callback_func_P(NavigationToolbar2TK):
def wrapper():
print('Plot on min/max from toolbar')
sg.popup('This window blocks main loop.\nPlot, Exit and Alive? buttons not working after that.\nAnd Terminal window could be closed by x only!')
return wrapper
class Toolbar(NavigationToolbar2Tk):
def __init__(self, *args, **kwargs):
self.toolitems = NavigationToolbar2Tk.toolitems+((None, None, None, None),)
super(Toolbar, self).__init__(*args, **kwargs)
self._buttons["Plotmm"] = button = self._Button("Plotmm", get_res_file_path('axsminmax.png'), toggle=False, command=callback_func_P(self))
Tooltip = getattr(matplotlib.backends, '_backend_tk').ToolTip
Tooltip.createToolTip(button, "Plot data on min/max")
# ------------------------------- PySimpleGUI CODE
layout = [
[sg.T('Graph: y=sin(x)')],
[sg.B('Plot'), sg.B('Exit')],
[sg.T('Controls:')],
[sg.Canvas(key='controls_cv')],
[sg.T('Figure:')],
[sg.Column(
layout=[
[sg.Canvas(key='fig_cv',
# it's important that you set this size
size=(400 * 2, 400)
)]
],
background_color='#DAE0E6',
pad=(0, 0)
)],
[sg.B('Alive?')]
]
window = sg.Window('Graph with controls', layout)
while True:
event, values = window.read()
print(event, values)
if event in (sg.WIN_CLOSED, 'Exit'): # always, always give a way out!
break
elif event is 'Plot':
# ------------------------------- PASTE YOUR MATPLOTLIB CODE HERE
plt.figure(1)
fig = plt.gcf()
DPI = fig.get_dpi()
# ------------------------------- you have to play with this size to reduce the movement error when the mouse hovers over the figure, it's close to canvas size
fig.set_size_inches(404 * 2 / float(DPI), 404 / float(DPI))
# -------------------------------
x = np.linspace(0, 2 * np.pi)
y = np.sin(x)
plt.plot(x, y)
plt.title('y=sin(x)')
plt.xlabel('X')
plt.ylabel('Y')
plt.grid()
# ------------------------------- Instead of plt.show()
draw_figure_w_toolbar(window['fig_cv'].TKCanvas, fig, window['controls_cv'].TKCanvas)
window.close()
If instead of sg.popup we'll create our own window the result will be same.
Steps to reproduce.
1.Start script.
2.Press button Plot.
3.Press most right toolbar' button (tooltip-'Plot data on min/max').
4.Press Plot or Exit buttons - nothing is happen.
Know nothing about the relation between function wrapper and tkinter.
My suggestion is to use method window.write_event_value to generate an event to main loop to do something about the GUI.
def callback_func_P(NavigationToolbar2TK):
def wrapper():
print('Plot on min/max from toolbar')
window.write_event_value('Popup', 'This window blocks main loop.\nPlot, Exit and Alive? buttons not working after that.\nAnd Terminal window could be closed by x only!')
return wrapper
and this in the main event loop
elif event == 'Popup':
sg.popup(values[event])

pyqtgrapgh: Image Item not in the center of GraphicsView

I am using pyqtgraph to visualate 2D arrays. Due to the fact that I have to refresh the visualated Image because of a real time application which I want to evaluate I am using GraphicsView(). Then I create a ImageItem and I want to add the Item to the created window. Unfortunately the image is only visible in the left upper corner of the window. I know that I can show the full image without GraphicsView but as I said I will need GraphicsView later to visualate the updated values in real time for an application.
Here is my current code:
import numpy as np
from pyqtgraph.Qt import QtGui, QtCore
import pyqtgraph as pg
import struct
import sounddevice as sd
from scipy.fftpack import fft
import sys
import time
class Fenster(pg.GraphicsLayoutWidget): #objektorientiert arbeiten!!
def __init__(self): #constructor
super().__init__() #ruft den constructor von QWidget auf
self.initMe()
class Fenster(pg.GraphicsLayoutWidget):
def __init__(self):
super().__init__()
self.initMe()
def initMe(self):
self.win = pg.GraphicsView()
self.win.show()
self.plot_data = np.fromfunction(lambda i, j: (1+0.3*np.sin(i)) * (i)**2 + (j)**2, (100, 100))
self.img = pg.ImageItem(image=self.plot_data)
self.cm = pg.colormap.get('CET-L9')
self.bar = pg.ColorBarItem( values= (0, 20_000), colorMap=self.cm )
self.bar.setImageItem(self.img)
self.win.setCentralItem(self.img)
w = Fenster()
That is the output image:
How can I set that the image fullfill the whole window?
How can I do that the created ColorBarItem will be showed in the window? (optionally)
Thanks in advance.
I found the solution. You have to create a PlotItem. Then add the ImageItem to the PlotItem and set the PlotItem in the center of GraphicsView
self.win = pg.GraphicsView()
self.win.show()
self.p = pg.PlotItem()
self.win.setCentralItem(self.p)
self.plot_data = np.fromfunction(lambda i, j: (1+0.3*np.sin(i)) * (i)**2 + (j)**2, (100, 100))
self.img = pg.ImageItem(image=self.plot_data)
self.cm = pg.colormap.get('CET-L9')
self.bar = pg.ColorBarItem( values= (0, 20_000), colorMap=self.cm )
self.bar.setImageItem(self.img)
self.p.addItem(self.img)
I also figured out to update the plot (live plot). Leave a comment if I should share.

PySide6 QListWidget dragging a row to its index deletes the row

import sys, os
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
from ui_listitem import *
class myItem(QWidget):
def __init__(self, parent = None) -> None:
super().__init__(parent=parent)
self.ui = Ui_rootWidget() # this ui just have 2 text labels horizontal aligned
self.ui.setupUi(self)
class myList(QListWidget):
def __init__(self, parent = None) -> None:
super().__init__(parent=parent)
self.resize(400, 400)
self.setDragDropMode(QAbstractItemView.DragDropMode.InternalMove)
for i in range(10):
wi = QListWidgetItem(self)
wi.widget = myItem(self)
wi.widget.ui.label1.setText(f'text{i}')
wi.widget.ui.label2.setText(f'text{i}')
wi.setSizeHint(wi.widget.sizeHint())
self.addItem(wi)
self.setItemWidget(wi, wi.widget)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = myList()
w.show()
sys.exit(app.exec())
result:
uh..I don't know what it happened. What should I do to get it to work?
I read a post(InternalMove in QListWidget makes item disappear). I tried setDefaultDropAction(Qt.TargetMoveAction) or setMovement(QListView.Free) or both but not worked.
I am using python 3.9.7, pyside 6.2.1, on Windows 10 Pro 20H2 19042.1348 build.
Addition.
A similar but not identical disappearance occurs in a QListView without a custom widget.
import sys, os
from PySide6.QtCore import *
from PySide6.QtGui import *
from PySide6.QtWidgets import *
class myDelegate(QStyledItemDelegate):
def sizeHint(self, option, index):
return QSize(350, 35)
class myList(QListView):
def __init__(self, parent = None) -> None:
super().__init__(parent=parent)
self.resize(400, 400)
self.setDragDropMode(QAbstractItemView.DragDropMode.InternalMove)
self.model = QStandardItemModel(self)
self.setModel(self.model)
self.delegate = myDelegate(self)
self.setItemDelegate(self.delegate)
for i in range(10):
item = QStandardItem(f'text{i}')
self.model.appendRow(item)
self.setDragDropOverwriteMode(False)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = myList()
w.show()
sys.exit(app.exec())
result:
I tried setDefaultDropAction with Qt.MoveAction, Qt.CopyAction or Qt.TargetMoveAction but all not worked.
Are these all originally intended? Please let me know how to move items in listview or listwidget without disappearing. Or maybe it's impossible?

tkinter GUI freezes while plotting voltages of an Arduino

I am just trying to write a GUI to help me while measuring. For now, I want to be able to plot -Voltages for example- in real-time from my Arduino UNO. Sadly this code just works fine for around 5 seconds, after this the tkinter windows freezes. Amazingly the v and t list works. Would you please give me a hint to fix this problem? I just spend hours.
from pyfirmata import Arduino, util
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import *
import time
import threading
board=Arduino('COM3')
iterator = util.Iterator(board)
iterator.start()
Tvl = board.get_pin('a:0:i')
class mclass(threading.Thread):
def __init__(self, window):
threading.Thread.__init__(self)
self.window = window
self.box = Entry(window)
self.button = Button (window, text="check", command=self.plot)
self.box.pack ()
self.button.pack()
self.t=[]
self.v=[]
self.fig = Figure(figsize=(6,6))
self.a = self.fig.add_subplot(111)
self.a.invert_yaxis()
self.a.set_title ("Estimation Grid", fontsize=16)
self.a.set_ylabel("Y", fontsize=14)
self.a.set_xlabel("X", fontsize=14)
self.canvas = FigureCanvasTkAgg(self.fig, master=self.window)
self.canvas.get_tk_widget().pack(side=BOTTOM, fill=BOTH, expand=False)
def plot (self):
global t,v
clock=time.perf_counter()
while time.perf_counter()-clock<=float(self.box.get()):
self.v.append(Tvl.read())
self.t.append(time.perf_counter()-clock)
if len(self.v)>=25:
del self.v[0]
del self.t[0]
self.a.clear()
self.a.plot(self.t,self.v)
self.canvas.draw()
window= Tk()
t= mclass(window)
t.start()
window.mainloop()
I thank you for your comments. In the end patthoyts hint worked quite well. I would be verry interested why while loops in this case dont work.
Beneath ist the new stable Code with some more Features added.
thanks and greets peterudo
from pyfirmata import Arduino, util
import matplotlib
matplotlib.use('TkAgg')
from matplotlib.backends.backend_tkagg import FigureCanvasTkAgg
from matplotlib.figure import Figure
from tkinter import *
import time
import threading
board=Arduino('COM3')
iterator = util.Iterator(board)
iterator.start()
Tvl = board.get_pin('a:0:i')
class mclass(threading.Thread):
def __init__(self, window):
threading.Thread.__init__(self)
self.window = window
self.box = Entry(window)
self.box.pack ()
self.button = Button (window, text="check", command=self.plot)
self.button.pack()
self.button2 = Button(window,text="stop", command=self.start_stop)
self.button2.pack()
self.w=Scale(window, from_=0, to=10000)
self.w.pack()
self.w2=Scale(window, from_=0, to=100000)
self.w2.pack()
self.t=[]
self.v=[]
self.ss=True
self.fig = Figure(figsize=(6,6))
self.a = self.fig.add_subplot(111)
self.a.invert_yaxis()
self.a.set_title ("Estimation Grid", fontsize=16)
self.a.set_ylabel("Y", fontsize=14)
self.a.set_xlabel("X", fontsize=14)
self.canvas = FigureCanvasTkAgg(self.fig, master=self.window)
self.canvas.get_tk_widget().pack(side=BOTTOM, fill=BOTH, expand=False)
def plot (self):
window.after(10, self.plot)
if self.ss==True:
self.v.append(Tvl.read())
self.t.append(time.perf_counter())
if self.t[0]<self.t[len(self.t)-1]-0.0001*self.w2.get():
del self.v[0]
del self.t[0]
self.a.clear()
self.a.set_ylim(Tvl.read()-0.0001*self.w.get(),Tvl.read()+0.0001*self.w.get())
self.a.set_xlim(self.t[len(self.t)-1]-0.001*self.w2.get()+1,time.perf_counter())
self.a.plot(self.t,self.v)
self.canvas.draw()
def start_stop(self):
if self.ss==True:
self.ss=False
else:
self.ss=True
window= Tk()
t= mclass(window)
t.start()
window.mainloop()

Unable to implement mpl_connect

I'm working on a GUI that basically hold multiple widgets that each contain a figure as well as a few buttons/whatever. One of the figures is supposed to be interactive, calling a function whenever the user clicks on any part of the plot. Yet I can't get the function to fire using mpl_connect, even after playing with focus and whatnot. I'm somewhat new to PySide/Qt, so I don't exactly understand why my code is behaving like this (I've been searching for days for a solution, but haven't found anything about it).
I used Qt Designer to create the layout for the GUI. I'm using Spyder from Anaconda 2.2.0 (32-bit), Python 2.7, and PySide to develop the GUI. If it's any help, I come from more of a MATLAB background where I developed a full version of the GUI I'm trying to make in Python.
Below is the relevant code (scroll down a bit to see where the problem is):
from PySide import QtCore, QtGui
from PySide.QtCore import *
from PySide.QtGui import *
import numpy as np
import matplotlib
matplotlib.use('Qt4Agg')
matplotlib.rcParams['backend.qt4']='PySide'
from matplotlib.figure import Figure
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.backends.backend_qt4agg import NavigationToolbar2QTAgg as NavigationToolbar
import matplotlib.pyplot as plt
from PySide.QtGui import QPalette, QCursor
import matplotlib.colors as colors
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1316, 765)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.widget = QtGui.QWidget(self.centralwidget)
self.widget.setGeometry(QtCore.QRect(75, 40, 375, 490))
self.widget.setObjectName("widget")
color = self.centralwidget.palette().color(QPalette.Window)
self.leftPlot = MatplotlibWidget(None,'','','',False,color)
self.setupPlot(self.widget,self.leftPlot)
self.leftPlot.figure.tight_layout()
self.leftImage = self.leftPlot.axes.imshow(self.defaultSlide, cmap = mymap)
Snippet of interest:
self.leftPlot.figure.canvas.setFocusPolicy(QtCore.Qt.StrongFocus)
self.leftPlot.figure.canvas.setFocus()
cid = self.leftPlot.figure.canvas.mpl_connect('button_release_event', self.getCoordinates) # doesn't get called
plt.show()
def getCoordinates(self, event):
print 'dasdsadadsa'
print 'button=%d, x=%d, y=%d, xdata=%f, ydata=%f'%(event.button, event.x, event.y, event.xdata, event.ydata)
The rest:
class MatplotlibWidget(FigureCanvas):
def __init__(self, parent=None,xlabel='x',ylabel='y',title='Title',showTicks=False,color=None):
super(MatplotlibWidget, self).__init__(Figure())
self.setParent(parent)
if color != None:
self.figure = Figure(facecolor=(color.red()/256.0,color.green()/256.0,color.blue()/256.0),frameon=0)
else:
self.figure = Figure(frameon=0)
self.canvas = FigureCanvas(self.figure)
self.axes = self.figure.add_subplot(111)
self.axes.set_xlabel(xlabel)
self.axes.set_ylabel(ylabel)
self.axes.set_title(title)
self.axes.get_xaxis().set_visible(showTicks)
self.axes.get_yaxis().set_visible(showTicks)
class ControlMainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(ControlMainWindow, self).__init__(parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
plt.show()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mySW = ControlMainWindow()
mySW.show()
sys.exit(app.exec_())
I'm aware the code is messy, but any input is greatly appreciated.
Update (2015-09-04) : I've updated the MWE I provided as part of my original answer to use instead the approach that is suggested in the matplotlib documentation to embed a mpl figure in an application. This approach does not use the pyplot interface (as in my original answer) and use the Object Oriented API of mpl instead. Also, since all the mpl artists (figure, axes, etc.) know each other, there is no need to explicitly create new class variables. This allows a structure of code that is, IMO, easier to read and to maintain.
The problem comes from the fact that you are not connecting correctly your event to self.leftPlot (FigureCanvasQTAgg), but to self.leftPlot.figure.canvas (FigureCanvasQTAgg.figure.FigureCanvasQTAgg) instead. You are creating a canvas within a canvas in the MatplotlibWidget class (which is already a subclass of FigureCanvasQTAgg). You only need to create one mpl canvas, pass a figure to it, and then connect the event to it directly.
I've put together a MWE to demonstrate how this can be done using the Object Oriented API of Matplotlib as suggested in the documentation:
from PySide import QtGui
import numpy as np
import sys
import matplotlib as mpl
mpl.use('Qt4Agg')
mpl.rcParams['backend.qt4']='PySide'
from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg
class ControlMainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(ControlMainWindow, self).__init__(parent)
self.setupUi()
def setupUi(self):
figure = mpl.figure.Figure(figsize=(5, 5))
leftPlot = MatplotlibWidget(figure)
self.setCentralWidget(leftPlot)
class MatplotlibWidget(FigureCanvasQTAgg):
def __init__(self, fig):
super(MatplotlibWidget, self).__init__(fig)
#-- set up an axe artist --
ax = fig.add_axes([0.1, 0.1, 0.85, 0.85])
ax.plot(np.arange(15), np.arange(15))
self.draw()
#---- setup event ----
self.mpl_connect('button_press_event', self.onclick)
def onclick(self, event):
x, y = event.x, event.y
print(x, y)
if x != None and y != None:
ax = self.figure.axes[0]
ax.plot(event.xdata, event.ydata, 'ro')
self.draw()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mySW = ControlMainWindow()
mySW.show()
sys.exit(app.exec_())
The code above results in:

Resources