-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUi_test.py
43 lines (34 loc) · 1.35 KB
/
GUi_test.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
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
import numpy as np
pic = np.arange(1,3*300*300+1).reshape(3,300,300)
class picture(QWidget):
def __init__(self):
super(picture, self).__init__()
self.resize(600, 400)
self.setWindowTitle("label显示图片")
self.label = QLabel(self)
self.label.setText(" 显示图片")
self.label.setFixedSize(150, 200)
self.label.move(60, 160)
self.label.setStyleSheet("QLabel{background:white;}"
"QLabel{color:rgb(300,300,300,120);font-size:10px;font-weight:bold;font-family:宋体;}"
)
btn = QPushButton(self)
btn.setText("打开图片")
btn.move(10, 30)
btn.clicked.connect(self.openimage)
jpg = QtGui.QPixmap(pic).scaled(self.label.width(), self.label.height())
self.label.setPixmap(jpg)
def openimage(self):
imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "", "*.jpg;;*.png;;All Files(*)")
jpg = QtGui.QPixmap(pic).scaled(self.label.width(), self.label.height())
self.label.setPixmap(jpg)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
my = picture()
my.show()
sys.exit(app.exec_())