I'm having trouble trying to undersand how the window objects work. I have a real time plot on a secundary window via matplotlib. This plot updates every second with the new calculated values.
What I expect is the method to stop running whenever I close this 2nd window and restarts when I reopen it. I'm able to reset the array values when I'm closing the 2nd window but as indicated, this method calculating the values is still running.
This is my code (originally using a sensor, I modified this to generate random numbers instead):
from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
import sys
import random
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
# The main window
class Window(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(200,200, 400,300)
self.setWindowTitle('Test')
self.demo = None
self.create_buttons()
def create_buttons(self):
btn1 = QPushButton('Open window', self)
btn1.setGeometry(100,100, 100,100)
btn1.clicked.connect(self.open_w)
def open_w(self):
if self.demo is None:
self.demo = AppDemo()
self.demo.show()
# Second window, where I plot the data
class AppDemo(QWidget):
def __init__(self):
super().__init__()
self.resize(650, 500)
self.plotwidget = QWidget(self)
self.chart = Matplotlibwidget()
self.chart.plot_widget(self.plotwidget, self.chart)
def closeEvent(self, event):
event.accept()
func.start_lists()
print('Window closed')
# My widget for my graph
class Matplotlibwidget(FigureCanvas):
def __init__(self, parent=None):
fig = Figure()
self.axes = fig.add_subplot(111)
FigureCanvas.__init__(self, fig)
self.setParent(parent)
FigureCanvas.updateGeometry(self)
def plot_widget(self, canvasWidget, graph):
self.layoutvertical = QVBoxLayout(canvasWidget)
self.layoutvertical.addWidget(graph)
timer = QtCore.QTimer(self)
timer.timeout.connect(self.plotting)
timer.start(1000)
def plotting(self):
self.y = func.calculate()
func.appends(self.y)
self.axes.cla()
self.axes.plot(func.x, func.y)
self.draw()
# This is a generic class I use to calculate the data, originally this is a class for my sensor
class FuncTime ():
def __init__(self):
self.start_lists()
def start_lists(self):
self.x, self.y = [0], [1]
def calculate(self):
return self.y[-1] + self.y[-1] * random.uniform(-0.1, 0.1)
def appends(self, y):
print(self.x[-1], ', ', self.y[-1])
self.x.append(self.x[-1] + 1)
self.y.append(y)
app = QApplication(sys.argv)
func = FuncTime()
window = Window()
window.show()
sys.exit(app.exec_())
That the window closes does not imply that the timer stops, you have to implement it using the stop method of the QTimer.
from functools import cached_property
import random
import sys
from PyQt5.QtCore import QTimer
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QVBoxLayout
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
class Window(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(200, 200, 400, 300)
self.setWindowTitle("Test")
self.create_buttons()
#cached_property
def demo(self):
return AppDemo()
def create_buttons(self):
btn1 = QPushButton("Open window", self)
btn1.setGeometry(100, 100, 100, 100)
btn1.clicked.connect(self.open_w)
def open_w(self):
self.demo.chart.start()
self.demo.show()
class AppDemo(QWidget):
def __init__(self):
super().__init__()
self.resize(650, 500)
self.chart = Matplotlibwidget()
lay = QVBoxLayout(self)
lay.addWidget(self.chart)
def closeEvent(self, event):
super().closeEvent(event)
self.chart.stop()
class Matplotlibwidget(FigureCanvas):
def __init__(self, parent=None):
fig = Figure()
self.axes = fig.add_subplot(111)
FigureCanvas.__init__(self, fig)
self.setParent(parent)
self.updateGeometry()
#cached_property
def timer(self):
return QTimer(interval=1000, timeout=self.handle_timeout)
#cached_property
def func_time(self):
return FuncTime()
def start(self):
self.timer.start()
def stop(self):
self.timer.stop()
self.func_time.reset()
def handle_timeout(self):
self.plotting()
def plotting(self):
self.y = self.func_time.calculate()
self.func_time.appends(self.y)
self.axes.cla()
self.axes.plot(self.func_time.x, self.func_time.y)
self.draw()
class FuncTime:
def __init__(self):
self.reset()
def reset(self):
self.x, self.y = [0], [1]
def calculate(self):
return self.y[-1] + self.y[-1] * random.uniform(-0.1, 0.1)
def appends(self, y):
print(self.x[-1], ", ", self.y[-1])
self.x.append(self.x[-1] + 1)
self.y.append(y)
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
Related
Currently, my code can paint an ellipse but every time I click the mouse for a new ellipse the previous ellipse will not retain .
I am used the **QGraphicsView** Framework because I am using its pantool and zoom function but I have a hard time adding the paint function.
import sys
from PyQt5.QtCore import Qt, QRectF, QPointF
from PyQt5.QtGui import QPixmap, QTransform, QBrush, QColor, QPen, QPainterPath
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QVBoxLayout, QGraphicsView,
QGraphicsScene, QGraphicsPixmapItem, QSizePolicy, QSpacerItem, QGraphicsObject
class MouseBrushObject(QGraphicsObject):
def __init__(self):
QGraphicsObject.__init__(self)
self._size = 10
self._x = 0
self._y = 0
self._pen = None
self._brush = None
self._color = None
self.setColor(QColor(255, 0, 0, 255))
def paint(self, painter, option, widget):
rect = self.boundingRect()
painter.setPen(self._pen)
painter.setBrush(self._brush)
painter.drawEllipse(QPointF(self._x,self._y), 5,5)
def boundingRect(self):
return QRectF(self._x, self._y, self._size, self._size)
def setColor(self, color):
self._color = color
self._pen = QPen(self._color, 1)
self._brush = QBrush(QColor(self._color.red(), self._color.green(), self._color.blue(), 40))
def setSize(self, size):
self._size = size
def setPosition(self, pos):
self._x = pos.x() - pos.x()/2
self._y = pos.y() - pos.y()/2
self.setPos(QPointF(self._x, self._y))
class View(QGraphicsView):
def __init__(self, parent=None):
QGraphicsView.__init__(self, parent=parent)
self.setMouseTracking(True)
self.scene = QGraphicsScene(self)
self.setScene(self.scene)
pixmap = QPixmap(300, 300)
self.scene.addItem(QGraphicsPixmapItem(pixmap))
#self.setTransform(QTransform().scale(1, 1).rotate(0))
self.scene.setBackgroundBrush(QBrush(Qt.lightGray))
self._brushItem = MouseBrushObject()
self.path = QPainterPath()
def mousePressEvent(self, event):
pos = event.pos()
self._brushItem.setPosition(pos)
def enterEvent(self, event):
self.scene.addItem(self._brushItem)
return super(View, self).enterEvent(event)
def leaveEvent(self, event):
self.scene.removeItem(self._brushItem)
return super(View, self).leaveEvent(event)
class Viewer(QWidget):
def __init__(self, parent=None):
QWidget.__init__(self, parent=parent)
layout = QVBoxLayout()
self.view = View(self)
self.setLayout(layout)
layout.addWidget(self.view)
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.viewer = Viewer(self)
layout = QVBoxLayout()
layout.addWidget(self.viewer)
centralwidget = QWidget(self)
centralwidget.setLayout(layout)
self.setCentralWidget(centralwidget)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = MainWindow()
main.show()
sys.exit(app.exec_())
Every time the mousePressEvent is trigger, it will paint an ellipse but the problem is that it will not retain the previous ellipse will adding the new ellipse.
My goal is for this code is two paint an ellipse when the mouse is clicked as it will serve as a point. Then The two points will be automatically connect using path. I have tried it will the qpainter function and it works but since I can't used qpaintEvent in QgraphicsView, I have a hard time executing the code.
Maybe I'm doing this completely wrong here, I'm trying to make the "timeline" for an mp3 player. Everything works and I've tried to set the slider to one value and it was fine. My problem is when I try updating the timeline as it keeps on freezing the program and it doesn't unfreeze. Here's my code, I commented out where to start looking at in terms of where I'm having trouble in:
import sys
from PyQt5.QtCore import QCoreApplication, Qt
from PyQt5.QtGui import *
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QPushButton,
QSlider
import vlc
player = vlc.MediaPlayer("/songs/Immigrant Song.mp3")
class window(QMainWindow):
def __init__(self):
super(window, self).__init__()
self.setGeometry(50, 50, 400, 200)
self.setWindowTitle('SlugPlayer')
#self.setWindowIcon(QIcon('pic.png'))
self.home()
def home(self):
playing = 0
btn = QPushButton('quit', self)
btn.clicked.connect(self.close_application)
btn.resize(btn.sizeHint()) #set to acceptable size automatic
btn.move(0, 0)
playbtn = QPushButton('Play', self)
# playbtn.clicked.connect(self.update_bar, playing)
playbtn.clicked.connect(self.play_music, playing)
playbtn.resize(playbtn.sizeHint())
playbtn.move(100, 0)
psebtn = QPushButton('Pause', self)
psebtn.clicked.connect(self.pause_music, playing)
psebtn.resize(psebtn.sizeHint())
psebtn.move(200, 0)
stopbtn = QPushButton('Stop', self)
stopbtn.clicked.connect(self.stop_music, playing)
stopbtn.resize(stopbtn.sizeHint())
stopbtn.move(300, 0)
self.sl = QSlider(Qt.Horizontal, self)
self.sl.setFocusPolicy(Qt.NoFocus)
self.sl.setGeometry(30, 50, 300, 20)
self.sl.setMinimum(0)
self.sl.setMaximum(100)
self.sl.setValue(0)
self.sl.move(50, 100)
# self.sl.valueChanged[int].connect(self.print_value)
self.show()
def close_application(self):
sys.exit()
#here is where I'm trying to update the bar
def play_music(self, playing):
player.play()
playing = 1
while playing == 1:
self.update_bar(playing)
def pause_music(self, playing):
player.pause()
playing = 0
def stop_music(self, playing):
player.stop()
playing = 0
def print_value(self, value):
print(value)
#function to update the bar (converts to an int)
def update_bar(self, playing):
self.sl.setValue(int(player.get_position() * 100))
def run():
app = QApplication(sys.argv)
Gui = window()
sys.exit(app.exec_())
run()
An infinite loop like while playing == 1 freezes the GUI since it does not allow you to do other tasks, in these cases it is better to use a QTimer. Going a little further to the bottom of the problem I have implemented a class that is in charge of managing the player by sending signals when necessary.
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
import vlc
class VLCManager(QtCore.QObject):
durationChanged = QtCore.pyqtSignal(int)
positionChanged = QtCore.pyqtSignal(int)
def __init__(self, parent=None):
super(VLCManager, self).__init__(parent)
self._player = vlc.MediaPlayer()
self._timer = QtCore.QTimer(self, interval=100, timeout=self.update_values)
def setFileName(self, filename):
self._player = vlc.MediaPlayer(filename)
def position(self):
self.durationChanged.emit(self.duration())
return self._player.get_time()
def setPosition(self, time):
if self.position() != time:
self._player.set_time(time)
#QtCore.pyqtSlot()
def update_values(self):
self.positionChanged.emit(self.position())
def duration(self):
return self._player.get_length()
#QtCore.pyqtSlot()
def play(self):
self._player.play()
self.update_values()
self._timer.start()
#QtCore.pyqtSlot()
def pause(self):
self._player.pause()
self.update_values()
self._timer.stop()
#QtCore.pyqtSlot()
def stop(self):
self._player.stop()
self.update_values()
self._timer.stop()
class window(QtWidgets.QMainWindow):
def __init__(self):
super(window, self).__init__()
self._manager = VLCManager(self)
self._manager.setFileName("/songs/Immigrant Song.mp3")
self.setWindowTitle('SlugPlayer')
self.home()
def home(self):
quitbtn = QtWidgets.QPushButton('quit')
quitbtn.clicked.connect(self.close)
playbtn = QtWidgets.QPushButton('Play')
playbtn.clicked.connect(self._manager.play)
psebtn = QtWidgets.QPushButton('Pause', self)
psebtn.clicked.connect(self._manager.pause)
stopbtn = QtWidgets.QPushButton('Stop', self)
stopbtn.clicked.connect(self._manager.stop)
self.sl = QtWidgets.QSlider(orientation=QtCore.Qt.Horizontal)
self.sl.setFocusPolicy(QtCore.Qt.NoFocus)
self._manager.durationChanged.connect(self.sl.setMaximum)
self._manager.positionChanged.connect(self.sl.setValue)
central_widget = QtWidgets.QWidget()
self.setCentralWidget(central_widget)
lay = QtWidgets.QVBoxLayout(central_widget)
hlay = QtWidgets.QHBoxLayout()
for b in (quitbtn, playbtn, psebtn, stopbtn, ):
hlay.addWidget(b)
lay.addLayout(hlay)
lay.addWidget(self.sl)
self.sl.valueChanged[int].connect(self._manager.setPosition)
self.show()
def run():
app = QtWidgets.QApplication(sys.argv)
Gui = window()
sys.exit(app.exec_())
run()
I have a bit when try change new window UI with effect fade. I added effect on closeEvent of mainwindow but it doen't work.
This is my code:
library used:
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5 import uic
load ui
uifile_1 = 'home.ui'
form_1, base_1 = uic.loadUiType(uifile_1)
uifile_2 = 'plate.ui'
form_2, base_2 = uic.loadUiType(uifile_2)
Class Home page:
class HomePage(base_1, form_1):
def __init__(self):
super(base_1,self).__init__()
self.setupUi(self)
#add button for click next page
self.btn_start = QPushButton(self)
self.btn_start.clicked.connect(self.change)
self._heightMask = self.height()
self.animation = QPropertyAnimation(self, b"heightPercentage")
self.animation.setDuration(1000)
self.animation.setStartValue(self.height())
self.animation.setEndValue(-1)
self.animation.finished.connect(self.close)
self.isStarted = False
def change(self):
self.plate = PlatePage()
self.plate.show()
self.close()
#pyqtProperty(int)
def heightMask(self):
return self._heightMask
#heightMask.setter
def heightPercentage(self, value):
self._heightMask = value
rect = QRect(0, 0, self.width(), self.heightMask)
self.setMask(QRegion(rect))
def closeEvent(self, event):
if not self.isStarted:
self.animation.start()
self.isStarted = True
event.ignore()
else:
self.closeEvent(self, event)
Class Plate Page
class PlatePage(base_2, form_2):
def __init__(self):
super(base_2, self).__init__()
self.setupUi(self)
self.show()
Please have a look and give me some solution.
Thank You
Try it:
from PyQt5.QtCore import QPropertyAnimation, QThread
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QPushButton
class Window(QWidget):
def __init__(self, *args, **kwargs):
super(Window, self).__init__(*args, **kwargs)
self.resize(400, 400)
layout = QVBoxLayout(self)
layout.addWidget(QPushButton('Button', self))
self.animation = QPropertyAnimation(self, b'windowOpacity')
self.animation.setDuration(1000)
self.isStarted = False
self.doShow()
def doShow(self):
try:
self.animation.finished.disconnect(self.close)
except:
pass
self.animation.stop()
self.animation.setStartValue(0)
self.animation.setEndValue(1)
self.animation.start()
def closeEvent(self, event):
if not self.isStarted:
self.animation.stop()
self.animation.finished.connect(self.close)
self.animation.setStartValue(1)
self.animation.setEndValue(0)
self.animation.start()
self.isStarted = True
event.ignore()
else:
event.accept()
if __name__ == '__main__':
import sys
from PyQt5.QtWidgets import QApplication
app = QApplication(sys.argv)
w = Window()
w.show()
sys.exit(app.exec_())
Following code creates a Widget with a Button and a Progressbar. When Button is pressed and Progressbar reaches 100%, 3 plots are shown (by Matplotlib.pyplot):
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import matplotlib.pyplot as plt
import pandas as pd
class App(QMainWindow):
def __init__(self):
super(App, self).__init__()
self.setGeometry(500, 300, 820, 350)
self.setWindowTitle("Program")
#Buttons
btnposx = 30
btnposy = 50
self.btn4 = QPushButton('Load', self)
self.btn4.move(btnposx,btnposy+220)
self.btn4.released.connect(self.thread)
#ProgressBar
self.pb = QProgressBar(self)
self.pb.move(btnposx+150,btnposy+220)
self.pb.resize(470,27)
self.show()
#pyqtSlot(float)
def load(self, val):
self.pb.setValue(val)
#pyqtSlot(object)
def plot(self, pq):
pq.plot(grid = 1)
plt.show()
def thread(self):
self.thread_ = Thread()
self.thread_.pb_signal.connect(self.load, Qt.QueuedConnection)
self.thread_.plot_signal.connect(self.plot, Qt.QueuedConnection)
self.thread_.start()
class Thread(QThread):
pb_signal = pyqtSignal(float)
plot_signal = pyqtSignal(object)
def __init__(self, *args, **kwargs):
QThread.__init__(self, *args, **kwargs)
def __del__(self):
self.wait()
#pyqtSlot()
def run(self):
val = 0
self.pb_signal.emit(20)
l = range(50000000)
for i in l:
val += 1
self.pb_signal.emit(60)
self.pb_signal.emit(100)
pq = pd.DataFrame(data = {'col1':[1,2,3,4,5,6], 'col2':[6,5,4,3,2,1]})
self.plot_signal.emit(pq)
self.plot_signal.emit(pq)
self.plot_signal.emit(pq)
return
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
ex.show()
sys.exit(app.exec_())
How do I do the exact same Thing with FigureCanvas? I don't want to make one window, in that 3 plots are embedded but 3 seperate figures. The Information online about how to use FigureCanvas this way is very scarce.
FigureCanvas is a specialized QWidget that can contain a Figure of matplotlib, and in that Figure you can make the plots, so the solution is to create one for each emission, in addition to that the plotting functions have an additional argument that receives the axes where it will be drawn, so you must pass the axes created inside Figure:
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
import pandas as pd
from matplotlib.backends.backend_qt4agg import (
FigureCanvas, NavigationToolbar2QT as NavigationToolbar)
from matplotlib.figure import Figure
class App(QMainWindow):
def __init__(self):
super(App, self).__init__()
self.setGeometry(500, 300, 820, 350)
self.setWindowTitle("Program")
#Buttons
btnposx = 30
btnposy = 50
self.btn4 = QPushButton('Load', self)
self.btn4.move(btnposx,btnposy+220)
self.btn4.released.connect(self.thread)
#ProgressBar
self.pb = QProgressBar(self)
self.pb.move(btnposx+150,btnposy+220)
self.pb.resize(470,27)
self.canvas = []
self.show()
#pyqtSlot(float)
def load(self, val):
self.pb.setValue(val)
#pyqtSlot(object)
def plot(self, pq):
cv = FigureCanvas(Figure(figsize=(5, 3)))
ax = cv.figure.subplots()
pq.plot(grid = 1, ax=ax)
cv.show()
# avoid garbage collector
self.canvas.append(cv)
def thread(self):
self.thread_ = Thread()
self.thread_.pb_signal.connect(self.load, Qt.QueuedConnection)
self.thread_.plot_signal.connect(self.plot, Qt.QueuedConnection)
self.thread_.start()
class Thread(QThread):
pb_signal = pyqtSignal(float)
plot_signal = pyqtSignal(object)
def __del__(self):
self.wait()
#pyqtSlot()
def run(self):
val = 0
self.pb_signal.emit(20)
l = range(50000000)
for i in l:
val += 1
self.pb_signal.emit(60)
self.pb_signal.emit(100)
pq = pd.DataFrame(data = {'col1':[1,2,3,4,5,6], 'col2':[6,5,4,3,2,1]})
self.plot_signal.emit(pq)
self.plot_signal.emit(pq)
self.plot_signal.emit(pq)
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
ex.show()
sys.exit(app.exec_())
Note: only the list has been created to prevent the garbage collector from deleting the plots
Here is some code I've written (and/or adapted from other sources):
import numpy as np
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
from PyQt5.QtWidgets import (QGraphicsView, QGraphicsScene, QMainWindow,
QApplication, QWidget, QVBoxLayout,
QDesktopWidget)
from PyQt5.QtGui import QBrush
from PyQt5.QtCore import Qt
import sys
class View(QGraphicsView):
def __init__(self):
super(View, self).__init__()
self.initScene()
def initScene(self):
self.scene = QGraphicsScene()
self.canvas = Fig()
self.setBackgroundBrush(QBrush(Qt.red))
self.canvas.draw()
self.setScene(self.scene)
self.scene.addWidget(self.canvas)
class Fig(FigureCanvas):
def __init__(self, *args,**kwargs):
self.factor = kwargs.pop("factor", 2)
FigureCanvas.__init__(self, Figure(), *args,**kwargs)
self.plot()
def plot(self):
self.ax = self.figure.add_subplot(111)
data = np.random.rand(1000)
self.ax.plot(data, '-')
class Window(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
desktop = QDesktopWidget()
rect = desktop.availableGeometry()
self.setGeometry(rect.width()/10, rect.height()/10, rect.width()/1.2,
rect.height()/1.2)
self.view = View()
self.setCentralWidget(self.view)
app = QApplication(sys.argv)
window = Window()
window.show()
app.exec_()
It produces the following window as its output:
I would like the plot in the middle to occupy as much space as possible, so that the red background becomes invisible.
This happens if I exclude the command setting the size of the window, that is indeed what happens. However, the window is then too small - I need to make it bigger.
I have tried using self.view.setGeometry, but it doesn't seem to make a difference. I've had a look at the available modules in the documentation, but can't tell which might help.
If you want to establish that the plot is shown covering all the available space within the window I see it unnecessary to use QGraphicsView since Fig is a QWidget that can be used directly in setCentralWidget():
class Fig(FigureCanvas):
def __init__(self, *args,**kwargs):
self.factor = kwargs.pop("factor", 2)
FigureCanvas.__init__(self, Figure(), *args,**kwargs)
self.plot()
def plot(self):
self.ax = self.figure.add_subplot(111)
data = np.random.rand(1000)
self.ax.plot(data, '-')
class Window(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
desktop = QDesktopWidget()
rect = desktop.availableGeometry()
self.setGeometry(rect.width()/10, rect.height()/10, rect.width()/1.2,
rect.height()/1.2)
self.canvas = Fig()
self.canvas.draw()
self.setCentralWidget(self.canvas)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())
update: Using QScrollArea
class Fig(FigureCanvas):
def __init__(self, *args,**kwargs):
self.factor = kwargs.pop("factor", 2)
FigureCanvas.__init__(self, Figure(), *args,**kwargs)
self.plot()
def plot(self):
self.ax = self.figure.add_subplot(111)
data = np.random.rand(1000)
self.ax.plot(data, '-')
def showEvent(self, event):
self.setFixedSize(self.size())
FigureCanvas.showEvent(self, event)
class Window(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
desktop = QDesktopWidget()
rect = desktop.availableGeometry()
self.setGeometry(rect.width()/10, rect.height()/10, rect.width()/1.2,
rect.height()/1.2)
self.canvas = Fig()
self.canvas.draw()
scrollArea = QScrollArea()
scrollArea.setWidgetResizable(True)
scrollArea.setWidget(self.canvas)
self.setCentralWidget(scrollArea)
if __name__ == '__main__':
app = QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())