当前位置:网站首页>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 :
边栏推荐
- Delphi read / write JSON format
- This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
- Use of vscode software
- Test d'automatisation de l'interface utilisateur télécharger manuellement le pilote du navigateur à partir de maintenant
- PlasticSCM 企业版Crack
- MySQL winter vacation self-study 2022 11 (10)
- Blue Bridge Cup single chip microcomputer -- PWM pulse width modulation
- DECLARE_ WAIT_ QUEUE_ HEAD、wake_ up_ Interruptible macro analysis
- Google Chrome CSS will not update unless the cache is cleared - Google Chrome CSS doesn't update unless clear cache
- UI自动化测试从此告别手动下载浏览器驱动
猜你喜欢

线程基础知识

【刷题】BFS题目精选

输入的查询SQL语句,是如何执行的?

error Couldn‘t find a package.json file in “你的路径“

A brief introduction to the behavior tree of unity AI

Rust区块琏开发——签名加密与私钥公钥
![[an Xun cup 2019] not file upload](/img/f1/736eb5fe51c299e3152ca87895ee99.png)
[an Xun cup 2019] not file upload

Installation of postman and postman interceptor
![[groovy] string (string splicing | multi line string)](/img/c7/2471d13e5d49cca3727d05b4f9fb36.jpg)
[groovy] string (string splicing | multi line string)
![[untitled]](/img/53/f67c53d4ada382ec42f97cf68d9c71.jpg)
[untitled]
随机推荐
ClickPaaS低代码平台
How to define a unified response object gracefully
UI自动化测试从此告别手动下载浏览器驱动
MindFusion.Virtual Keyboard for WPF
MySQL winter vacation self-study 2022 11 (9)
Timing manager based on C #
Binary heap implementation (priority queue implementation)
【PHP特性-变量覆盖】函数的使用不当、配置不当、代码逻辑漏洞
Basic function learning 02
测试开发是什么?为什么现在那么多公司都要招聘测试开发?
【无标题】
PlasticSCM 企业版Crack
Multimedia query
【做题打卡】集成每日5题分享(第三期)
为什么百度、阿里这些大厂宁愿花25K招聘应届生,也不愿涨薪5K留住老员工?
How rem is used
Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
EasyCVR更改录像存储路径,不生成录像文件如何解决?
[数组]566. 重塑矩阵-简单
Use of vscode software