import sys from PyQt5 import QtCore, QtGui, QtWidgets from PyQt5.QtGui import QPixmap from PyQt5.QtWidgets import QApplication, QLabel, QMainWindow, QFileDialog class Ui_MainWindow2(object): def setupUi(self,MainWindow2): MainWindow2.setObjectName("MainWindow2") MainWindow2.resize(1000, 650) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 230)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 230)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.Window, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 230)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Base, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 230)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.Window, brush) MainWindow2.setPalette(palette) self.centralwidget = QtWidgets.QWidget(MainWindow2) self.centralwidget.setObjectName("centralwidget") self.graphicsView = QtWidgets.QGraphicsView(self.centralwidget) self.graphicsView.setGeometry(QtCore.QRect(50, 60, 551, 381)) self.graphicsView.setObjectName("graphicsView") self.horizontalLayoutWidget = QtWidgets.QWidget(self.centralwidget) self.horizontalLayoutWidget.setGeometry(QtCore.QRect(50, 560, 401, 31)) self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget") self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget) self.horizontalLayout.setContentsMargins(0, 0, 0, 0) self.horizontalLayout.setObjectName("horizontalLayout") self.spinBox_left = QtWidgets.QSpinBox(self.horizontalLayoutWidget) self.spinBox_left.setObjectName("spinBox_left") self.horizontalLayout.addWidget(self.spinBox_left) self.spinBox_top = QtWidgets.QSpinBox(self.horizontalLayoutWidget) self.spinBox_top.setObjectName("spinBox_top") self.horizontalLayout.addWidget(self.spinBox_top) self.spinBox_right = QtWidgets.QSpinBox(self.horizontalLayoutWidget) self.spinBox_right.setObjectName("spinBox_right") self.horizontalLayout.addWidget(self.spinBox_right) self.spinBox_bottom = QtWidgets.QSpinBox(self.horizontalLayoutWidget) self.spinBox_bottom.setObjectName("spinBox_bottom") self.horizontalLayout.addWidget(self.spinBox_bottom) self.horizontalLayoutWidget_2 = QtWidgets.QWidget(self.centralwidget) self.horizontalLayoutWidget_2.setGeometry(QtCore.QRect(50, 530, 391, 31)) self.horizontalLayoutWidget_2.setObjectName("horizontalLayoutWidget_2") self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget_2) self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0) self.horizontalLayout_4.setObjectName("horizontalLayout_4") self.label_left = QtWidgets.QLabel(self.horizontalLayoutWidget_2) palette = QtGui.QPalette() brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 127, 128)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Active, QtGui.QPalette.PlaceholderText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 127, 128)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Inactive, QtGui.QPalette.PlaceholderText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 255)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.BrightText, brush) brush = QtGui.QBrush(QtGui.QColor(255, 255, 127, 128)) brush.setStyle(QtCore.Qt.SolidPattern) palette.setBrush(QtGui.QPalette.Disabled, QtGui.QPalette.PlaceholderText, brush) self.label_left.setPalette(palette) font = QtGui.QFont() font.setFamily("Carlito") font.setPointSize(9) self.label_left.setFont(font) self.label_left.setObjectName("label_left") self.horizontalLayout_4.addWidget(self.label_left) self.label_top = QtWidgets.QLabel(self.horizontalLayoutWidget_2) font = QtGui.QFont() font.setFamily("Carlito") font.setPointSize(9) self.label_top.setFont(font) self.label_top.setObjectName("label_top") self.horizontalLayout_4.addWidget(self.label_top) self.label_right = QtWidgets.QLabel(self.horizontalLayoutWidget_2) font = QtGui.QFont() font.setFamily("Carlito") font.setPointSize(9) self.label_right.setFont(font) self.label_right.setObjectName("label_right") self.horizontalLayout_4.addWidget(self.label_right) self.label_bottom = QtWidgets.QLabel(self.horizontalLayoutWidget_2) font = QtGui.QFont() font.setFamily("Carlito") font.setPointSize(9) self.label_bottom.setFont(font) self.label_bottom.setObjectName("label_bottom") self.horizontalLayout_4.addWidget(self.label_bottom) self.label_kadr = QtWidgets.QLabel(self.centralwidget) self.label_kadr.setGeometry(QtCore.QRect(50, 470, 131, 31)) font = QtGui.QFont() font.setFamily("Carlito") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.label_kadr.setFont(font) self.label_kadr.setObjectName("label_kadr") self.label_poyasneniye = QtWidgets.QLabel(self.centralwidget) self.label_poyasneniye.setGeometry(QtCore.QRect(50, 500, 401, 20)) self.label_poyasneniye.setObjectName("label_poyasneniye") self.pushButton_save = QtWidgets.QPushButton(self.centralwidget) self.pushButton_save.setGeometry(QtCore.QRect(680, 520, 261, 51)) font = QtGui.QFont() font.setFamily("Calibri Light") font.setPointSize(10) self.pushButton_save.setFont(font) self.pushButton_save.setObjectName("pushButton_save") self.pushButton_download = QtWidgets.QPushButton(self.centralwidget) self.pushButton_download.setGeometry(QtCore.QRect(280, 13, 261, 38)) font = QtGui.QFont() font.setFamily("Calibri Light") font.setPointSize(10) self.pushButton_download.setFont(font) self.pushButton_download.setObjectName("pushButton_download") self.label_povorot = QtWidgets.QLabel(self.centralwidget) self.label_povorot.setGeometry(QtCore.QRect(470, 470, 131, 31)) font = QtGui.QFont() font.setFamily("Carlito") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.label_povorot.setFont(font) self.label_povorot.setObjectName("label_povorot") self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget) self.verticalLayoutWidget.setGeometry(QtCore.QRect(470, 510, 131, 80)) self.verticalLayoutWidget.setObjectName("verticalLayoutWidget") self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget) self.verticalLayout.setContentsMargins(0, 0, 0, 0) self.verticalLayout.setObjectName("verticalLayout") self.pushButton_right = QtWidgets.QPushButton(self.verticalLayoutWidget) self.pushButton_right.setObjectName("pushButton_right") self.verticalLayout.addWidget(self.pushButton_right) self.pushButton_left = QtWidgets.QPushButton(self.verticalLayoutWidget) self.pushButton_left.setObjectName("pushButton_left") self.verticalLayout.addWidget(self.pushButton_left) self.label_filter = QtWidgets.QLabel(self.centralwidget) self.label_filter.setGeometry(QtCore.QRect(620, 60, 131, 31)) font = QtGui.QFont() font.setFamily("Carlito") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.label_filter.setFont(font) self.label_filter.setObjectName("label_filter") self.label_zagruzka = QtWidgets.QLabel(self.centralwidget) self.label_zagruzka.setGeometry(QtCore.QRect(50, 20, 241, 31)) font = QtGui.QFont() font.setFamily("Carlito") font.setPointSize(12) font.setBold(True) font.setWeight(75) self.label_zagruzka.setFont(font) self.label_zagruzka.setObjectName("label_zagruzka") self.formLayoutWidget = QtWidgets.QWidget(self.centralwidget) self.formLayoutWidget.setGeometry(QtCore.QRect(629, 100, 311, 341)) self.formLayoutWidget.setObjectName("formLayoutWidget") self.formLayout = QtWidgets.QFormLayout(self.formLayoutWidget) self.formLayout.setContentsMargins(0, 0, 0, 0) self.formLayout.setObjectName("formLayout") self.horizontalSlider_yarkost = QtWidgets.QSlider(self.formLayoutWidget) self.horizontalSlider_yarkost.setOrientation(QtCore.Qt.Horizontal) self.horizontalSlider_yarkost.setObjectName("horizontalSlider_yarkost") self.formLayout.setWidget(0, QtWidgets.QFormLayout.FieldRole, self.horizontalSlider_yarkost) self.label_yarkost = QtWidgets.QLabel(self.formLayoutWidget) font = QtGui.QFont() font.setFamily("Carlito") font.setPointSize(10) self.label_yarkost.setFont(font) self.label_yarkost.setObjectName("label_yarkost") self.formLayout.setWidget(0, QtWidgets.QFormLayout.LabelRole, self.label_yarkost) self.label_sepiya = QtWidgets.QLabel(self.formLayoutWidget) font = QtGui.QFont() font.setFamily("Carlito") font.setPointSize(10) self.label_sepiya.setFont(font) self.label_sepiya.setObjectName("label_sepiya") self.formLayout.setWidget(4, QtWidgets.QFormLayout.LabelRole, self.label_sepiya) self.label_otserogo = QtWidgets.QLabel(self.formLayoutWidget) font = QtGui.QFont() font.setFamily("Carlito") font.setPointSize(10) self.label_otserogo.setFont(font) self.label_otserogo.setObjectName("label_otserogo") self.formLayout.setWidget(2, QtWidgets.QFormLayout.LabelRole, self.label_otserogo) self.horizontalSlider_otserogo = QtWidgets.QSlider(self.formLayoutWidget) self.horizontalSlider_otserogo.setOrientation(QtCore.Qt.Horizontal) self.horizontalSlider_otserogo.setObjectName("horizontalSlider_otserogo") self.formLayout.setWidget(2, QtWidgets.QFormLayout.FieldRole, self.horizontalSlider_otserogo) self.horizontalSlider_sepiya = QtWidgets.QSlider(self.formLayoutWidget) self.horizontalSlider_sepiya.setOrientation(QtCore.Qt.Horizontal) self.horizontalSlider_sepiya.setObjectName("horizontalSlider_sepiya") self.formLayout.setWidget(4, QtWidgets.QFormLayout.FieldRole, self.horizontalSlider_sepiya) MainWindow2.setCentralWidget(self.centralwidget) self.menubar = QtWidgets.QMenuBar(MainWindow2) self.menubar.setGeometry(QtCore.QRect(0, 0, 1000, 26)) self.menubar.setObjectName("menubar") MainWindow2.setMenuBar(self.menubar) self.statusbar = QtWidgets.QStatusBar(MainWindow2) self.statusbar.setObjectName("statusbar") MainWindow2.setStatusBar(self.statusbar) self.retranslateUi(MainWindow2) QtCore.QMetaObject.connectSlotsByName(MainWindow2) self.pushButton_download.clicked.connect(self.start_OpenFile) # self.scene = QGraphicsScene() # self.graphicsView.setScene(self.scene) # self._pixmapHandle = None def retranslateUi(self, MainWindow2): _translate = QtCore.QCoreApplication.translate MainWindow2.setWindowTitle(_translate("MainWindow2", "MainWindow")) self.label_left.setText(_translate("MainWindow2", "Левая сторона")) self.label_top.setText( _translate("MainWindow2", "<html><head/><body><p align=\"center\"> Верх</p></body></html>")) self.label_right.setText(_translate("MainWindow2", " Правая сторона")) self.label_bottom.setText( _translate("MainWindow2", "<html><head/><body><p align=\"center\">Низ</p></body></html>")) self.label_kadr.setText(_translate("MainWindow2", "<html><head/><body><p>Кадрирование</p></body></html>")) self.label_poyasneniye.setText(_translate("MainWindow2", "<html><head/><body><p><span style=\" font-size:7pt;\">(увеличивайте или уменьшайте количество пикселей для обрезки)</span></p></body></html>")) self.pushButton_save.setText(_translate("MainWindow2", "Сохранить картинку")) self.pushButton_download.setText(_translate("MainWindow2", "Загрузить картинку")) self.label_povorot.setText(_translate("MainWindow2", "<html><head/><body><p>Поворот</p></body></html>")) self.pushButton_right.setText(_translate("MainWindow2", "Вправо")) self.pushButton_left.setText(_translate("MainWindow2", "Влево")) self.label_filter.setText(_translate("MainWindow2", "<html><head/><body><p>Фильтры</p></body></html>")) self.label_zagruzka.setText( _translate("MainWindow2", "<html><head/><body><p>Загрузите изображение</p></body></html>")) self.label_yarkost.setText(_translate("MainWindow2", "Яркость")) self.label_sepiya.setText(_translate("MainWindow2", "Сепия")) self.label_otserogo.setText(_translate("MainWindow2", "Оттенки серого")) #def initUI(self): # fname = QFileDialog.getOpenFileName( # self, 'Выбрать картинку', '', # 'Картинка (*.jpg);;Картинка (*.jpeg)')[0] #self.pixmap = QPixmap(fname) ##self.scene = QGraphicsScene() #self.graphicsView.setScene(self.scene) ## self.pushButton_download.clicked.connect(self.im_down) ## self.image = QLabel(self) ##self.image.move(80, 60) ##self.image.resize(250, 250) def im_down(self): self.image.setPixmap(self.pixmap) def hasImage(self): """ Returns whether or not the scene contains an image pixmap. """ return self._pixmapHandle is not None def clearImage(self): """ Removes the current image pixmap from the scene if it exists. """ if self.hasImage(): self.scene.removeItem(self._pixmapHandle) self._pixmapHandle = None def pixmap(self): """ Returns the scene's current image pixmap as a QPixmap, or else None if no image exists. :rtype: QPixmap | None """ if self.hasImage(): return self._pixmapHandle.pixmap() return None def image(self): """ Returns the scene's current image pixmap as a QImage, or else None if no image exists. :rtype: QImage | None """ if self.hasImage(): return self._pixmapHandle.pixmap().toImage() return None def setImage(self, image): """ Set the scene's current image pixmap to the input QImage or QPixmap. Raises a RuntimeError if the input image has type other than QImage or QPixmap. :type image: QImage | QPixmap """ if type(image) is QPixmap: pixmap = image elif type(image) is QImage: pixmap = QPixmap.fromImage(image) else: raise RuntimeError("ImageViewer.setImage: Argument must be a QImage or QPixmap.") if self.hasImage(): self._pixmapHandle.setPixmap(pixmap) else: self._pixmapHandle = self.scene.addPixmap(pixmap) self.setSceneRect(QRectF(pixmap.rect())) # Set scene size to image size. self.updateViewer() def loadImageFromFile2(self): print ("i am here") # fname = QFileDialog.getOpenFileName( # self, 'Выбрать картинку', '', # 'Картинка (*.jpg);;Картинка (*.jpeg)')[0] # print(fileName) def loadImageFromFile(self, fileName=""): """ Load an image from file. Without any arguments, loadImageFromFile() will popup a file dialog to choose the image file. With a fileName argument, loadImageFromFile(fileName) will attempt to load the specified image file directly. """ if len(fileName) == 0: if QT_VERSION_STR[0] == '4': fileName = QFileDialog.getOpenFileName(self, "Open image file.") elif QT_VERSION_STR[0] == '5': fileName, dummy = QFileDialog.getOpenFileName(self, "Open image file.") if len(fileName) and os.path.isfile(fileName): image = QImage(fileName) self.setImage(image) def updateViewer(self): """ Show current zoom (if showing entire image, apply current aspect ratio mode). """ if not self.hasImage(): return if len(self.zoomStack) and self.sceneRect().contains(self.zoomStack[-1]): self.fitInView(self.zoomStack[-1], Qt.IgnoreAspectRatio) # Show zoomed rect (ignore aspect ratio). else: self.zoomStack = [] # Clear the zoom stack (in case we got here because of an invalid zoom). self.fitInView(self.sceneRect(), self.aspectRatioMode) # Show entire image (use current aspect ratio mode). def start_OpenFile(self): print("i am here2") fname = QFileDialog.getOpenFileName(self, 'Выбрать картинку', '', 'Картинка (*.jpg);;Картинка (*.jpg);;Все файлы (*)')[0] print(fname) class mywindow2(QtWidgets.QMainWindow): def __init__(self): super(mywindow2, self).__init__() self.ui = Ui_MainWindow2() self.ui.setupUi(self) app = QtWidgets.QApplication([]) application = mywindow2() application.show() sys.exit(app.exec())
Write, Run & Share Python code online using OneCompiler's Python online compiler for free. It's one of the robust, feature-rich online compilers for python language, supporting both the versions which are Python 3 and Python 2.7. Getting started with the OneCompiler's Python editor is easy and fast. The editor shows sample boilerplate code when you choose language as Python or Python2 and start coding.
OneCompiler's python online editor supports stdin and users can give inputs to programs using the STDIN textbox under the I/O tab. Following is a sample python program which takes name as input and print your name with hello.
import sys
name = sys.stdin.readline()
print("Hello "+ name)
Python is a very popular general-purpose programming language which was created by Guido van Rossum, and released in 1991. It is very popular for web development and you can build almost anything like mobile apps, web apps, tools, data analytics, machine learning etc. It is designed to be simple and easy like english language. It's is highly productive and efficient making it a very popular language.
When ever you want to perform a set of operations based on a condition IF-ELSE is used.
if conditional-expression
#code
elif conditional-expression
#code
else:
#code
Indentation is very important in Python, make sure the indentation is followed correctly
For loop is used to iterate over arrays(list, tuple, set, dictionary) or strings.
mylist=("Iphone","Pixel","Samsung")
for i in mylist:
print(i)
While is also used to iterate a set of statements based on a condition. Usually while is preferred when number of iterations are not known in advance.
while condition
#code
There are four types of collections in Python.
List is a collection which is ordered and can be changed. Lists are specified in square brackets.
mylist=["iPhone","Pixel","Samsung"]
print(mylist)
Tuple is a collection which is ordered and can not be changed. Tuples are specified in round brackets.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
Below throws an error if you assign another value to tuple again.
myTuple=("iPhone","Pixel","Samsung")
print(myTuple)
myTuple[1]="onePlus"
print(myTuple)
Set is a collection which is unordered and unindexed. Sets are specified in curly brackets.
myset = {"iPhone","Pixel","Samsung"}
print(myset)
Dictionary is a collection of key value pairs which is unordered, can be changed, and indexed. They are written in curly brackets with key - value pairs.
mydict = {
"brand" :"iPhone",
"model": "iPhone 11"
}
print(mydict)
Following are the libraries supported by OneCompiler's Python compiler
Name | Description |
---|---|
NumPy | NumPy python library helps users to work on arrays with ease |
SciPy | SciPy is a scientific computation library which depends on NumPy for convenient and fast N-dimensional array manipulation |
SKLearn/Scikit-learn | Scikit-learn or Scikit-learn is the most useful library for machine learning in Python |
Pandas | Pandas is the most efficient Python library for data manipulation and analysis |
DOcplex | DOcplex is IBM Decision Optimization CPLEX Modeling for Python, is a library composed of Mathematical Programming Modeling and Constraint Programming Modeling |