当前位置:网站首页>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 :
边栏推荐
- ActiveReportsJS 3.1 VS ActiveReportsJS 3.0
- Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
- [groovy] loop control (number injection function implements loop | times function | upto function | downto function | step function | closure can be written outside as the final parameter)
- EasyCVR更改录像存储路径,不生成录像文件如何解决?
- Delphi free memory
- De debugging (set the main thread as hidden debugging to destroy the debugging Channel & debugger detection)
- Timing manager based on C #
- Kubernetes -- cluster expansion principle
- IronXL for .NET 2022.6
- This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
猜你喜欢
Deep learning - LSTM Foundation
Some enterprise interview questions of unity interview
[groovy] string (string type variable definition | character type variable definition)
JWT漏洞复现
Learning notes of raspberry pie 4B - IO communication (I2C)
@Transactional 注解导致跨库查询失效的问题
[安洵杯 2019]不是文件上传
Zero foundation uses paddlepaddle to build lenet-5 network
UI自動化測試從此告別手動下載瀏覽器驅動
grandMA2 onPC 3.1.2.5的DMX参数摸索
随机推荐
25K 入职腾讯的那天,我特么哭了
Clickhouse同步mysql(基于物化引擎)
NEW:Devart dotConnect ADO.NET
Clickhouse物化视图
Multimedia query
speed or tempo in classical music
【做题打卡】集成每日5题分享(第三期)
[wp][入门]刷弱类型题目
Deep learning - LSTM Foundation
Necessary fonts for designers
Unity implements the code of the attacked white flash (including shader)
Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
[安洵杯 2019]不是文件上传
Redis之Jedis如何使用
【PHP特性-变量覆盖】函数的使用不当、配置不当、代码逻辑漏洞
灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?
企业级:Spire.Office for .NET:Platinum|7.7.x
How rem is used
It took two nights to get Wu Enda's machine learning course certificate from Stanford University
How about programmers' eyesight| Daily anecdotes