当前位置:网站首页>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 :
边栏推荐
- C # use awaiter
- Clickhouse materialized view
- Deflocculant aminoiodotide eye drops
- PlasticSCM 企业版Crack
- MindFusion.Virtual Keyboard for WPF
- Zero foundation uses paddlepaddle to build lenet-5 network
- 25K 入职腾讯的那天,我特么哭了
- 特殊版:SpreadJS v15.1 VS SpreadJS v15.0
- [groovy] groovy environment setup (download groovy | install groovy | configure groovy environment variables)
- Anti debugging (basic principles of debugger Design & NT NP and other anti debugging principles)
猜你喜欢
De debugging (set the main thread as hidden debugging to destroy the debugging Channel & debugger detection)
How to define a unified response object gracefully
How is the entered query SQL statement executed?
线程基础知识
[wp][introduction] brush weak type questions
灵魂三问:什么是接口测试,接口测试怎么玩,接口自动化测试怎么玩?
Web components series (VII) -- life cycle of custom components
JWT漏洞复现
The new project Galaxy token just announced by coinlist is gal
An elegant program for Euclid‘s algorithm
随机推荐
[web Audit - source code disclosure] obtain source code methods and use tools
Assembly - getting started
面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?
Easy processing of ten-year futures and stock market data -- Application of tdengine in Tongxinyuan fund
glibc strlen 实现方式分析
An elegant program for Euclid‘s algorithm
error Couldn‘t find a package. JSON file in "your path“
How to make the listbox scroll automatically when adding a new item- How can I have a ListBox auto-scroll when a new item is added?
[数组]566. 重塑矩阵-简单
error Couldn‘t find a package.json file in “你的路径“
【web審計-源碼泄露】獲取源碼方法,利用工具
【软件逆向-基础知识】分析方法、汇编指令体系结构
[an Xun cup 2019] not file upload
Official announcement! The third cloud native programming challenge is officially launched!
ActiveReportsJS 3.1 VS ActiveReportsJS 3.0
【做题打卡】集成每日5题分享(第三期)
优先使用对象组合,而不是类继承
Some enterprise interview questions of unity interview
[deep learning] deep learning reference materials
Necessary fonts for designers