-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_tutorial.py
70 lines (57 loc) · 2.56 KB
/
image_tutorial.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'form.ui'
#
# Created by: PyQt5 UI code generator 5.15.4
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.picture = QtWidgets.QLabel(self.centralwidget)
self.picture.setGeometry(QtCore.QRect(190, 60, 371, 291))
self.picture.setAutoFillBackground(False)
self.picture.setText("")
# actually setting the picture to the widget
self.picture.setPixmap(QtGui.QPixmap("cat.jpg"))
self.picture.setScaledContents(True)
self.picture.setObjectName("picture")
self.Cat = QtWidgets.QPushButton(self.centralwidget)
self.Cat.setGeometry(QtCore.QRect(60, 390, 291, 71))
self.Cat.setObjectName("Cat")
self.Dog = QtWidgets.QPushButton(self.centralwidget)
self.Dog.setGeometry(QtCore.QRect(420, 390, 291, 71))
self.Dog.setObjectName("Dog")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 22))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
self.Dog.clicked.connect(self.show_dog)
self.Cat.clicked.connect(self.show_cat)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.Cat.setText(_translate("MainWindow", "Cat"))
self.Dog.setText(_translate("MainWindow", "Dog"))
def show_dog(self):
self.picture.setPixmap(QtGui.QPixmap("dog.webp"))
def show_cat(self):
self.picture.setPixmap(QtGui.QPixmap("cat.jpg"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())