当前位置:网站首页>Pyqt5 displays file names and pictures
Pyqt5 displays file names and pictures
2022-07-05 03:55:00 【*Program black*】
The code is as follows
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class picture(QWidget):
def __init__(self):
super(picture, self).__init__()
self.resize(600, 400)
self.setWindowTitle("label display picture ")
self.label = QLabel(self)
self.label.setText(" display picture ")
self.label.setFixedSize(int(410*2/3),int(410*2/3))
self.label.move(160, 100)
self.label.setStyleSheet("QLabel{background:white;}" "QLabel{color:rgb(300,300,300,120);font-size:15px;font-weight:bold;font-family: Song style ;}")
btn = QPushButton(self)
btn.setText(" Open the picture ")
btn.move(10, 30)
btn.clicked.connect(self.openimage)
cbtn = QPushButton(self)
cbtn.setText(" Select File ")
cbtn.move(10, 60)
cbtn.clicked.connect(self.changefiles)
self.labels = QLabel(self)
self.labels.setText('file ')
self.labels.move(150, 60)
def openimage(self):
imgName, imgType = QFileDialog.getOpenFileName(self, " Open the picture ", "", "*.jpg;;*.png;;All Files(*)")
print(imgName)
jpg = QtGui.QPixmap(imgName).scaled(self.label.width(), self.label.height())
self.label.setPixmap(jpg)
def changefiles(self):
# directory1 = QFileDialog.getExistingDirectory(self," Select a folder ","./") # Starting path
# print(directory1)
filePath, filetype = QFileDialog.getOpenFileName(self, " Select file ", "./","All Files(*)")
print(filePath)
self.labels.setText(filePath)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
my = picture()
my.show()
sys.exit(app.exec_())
Running results :
Open the picture :
Select File :
边栏推荐
- Subversive cognition: what does SRE do?
- About the recent experience of writing questions
- 线程基础知识
- 【无标题】
- EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
- Quick start of UI component development of phantom engine [umg/slate]
- UI自动化测试从此告别手动下载浏览器驱动
- Analysis of glibc strlen implementation mode
- Clickhouse物化视图
- Clickhouse synchronization MySQL (based on materialization engine)
猜你喜欢

Official announcement! The third cloud native programming challenge is officially launched!

Redis6-01nosql database
![[groovy] string (string splicing | multi line string)](/img/c7/2471d13e5d49cca3727d05b4f9fb36.jpg)
[groovy] string (string splicing | multi line string)
![[数组]566. 重塑矩阵-简单](/img/3c/593156f5bde67bd56828106d7bed3c.png)
[数组]566. 重塑矩阵-简单

Clickhouse物化视图
![[wp][introduction] brush weak type questions](/img/d0/9eb3ade701057837d98e4a20082a10.png)
[wp][introduction] brush weak type questions

This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises

EasyCVR更改录像存储路径,不生成录像文件如何解决?

Special Edition: spreadjs v15.1 vs spreadjs v15.0

About the recent experience of writing questions
随机推荐
Containerization Foundation
【web審計-源碼泄露】獲取源碼方法,利用工具
[数组]566. 重塑矩阵-简单
深度学习——LSTM基础
ActiveReportsJS 3.1 VS ActiveReportsJS 3.0
UI automation test farewell to manual download of browser driver
Operation flow of UE4 DMX and grandma2 onpc 3.1.2.5
NPM introduction link symbolic link
[vérification sur le Web - divulgation du code source] obtenir la méthode du code source et utiliser des outils
Use of vscode software
Zero foundation uses paddlepaddle to build lenet-5 network
[system security] ten thousand words summary system virtualization container bottom layer principle experiment
面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?
MySQL winter vacation self-study 2022 11 (9)
Clickhouse物化视图
Delphi read / write JSON format
MindFusion.Virtual Keyboard for WPF
[PHP features - variable coverage] improper use, improper configuration and code logic vulnerability of the function
[wp][introduction] brush weak type questions
Difference between MotionEvent. getRawX and MotionEvent. getX