当前位置:网站首页>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 :
边栏推荐
- Binary heap implementation (priority queue implementation)
- How to define a unified response object gracefully
- Zero foundation uses paddlepaddle to build lenet-5 network
- Analysis of glibc strlen implementation mode
- UI自动化测试从此告别手动下载浏览器驱动
- 【看完就懂系列】一文6000字教你从0到1实现接口自动化
- Containerization Foundation
- 一文带你了解BI的前世今身与企业数字化转型的关系
- DMX parameter exploration of grandma2 onpc 3.1.2.5
- 深度学习——LSTM基础
猜你喜欢

面试字节,过关斩将直接干到 3 面,结果找了个架构师来吊打我?

How to use jedis of redis

Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?

NEW:Devart dotConnect ADO. NET

An elegant program for Euclid‘s algorithm

IronXL for .NET 2022.6

The new project Galaxy token just announced by coinlist is gal

Redis6-01nosql database
![[groovy] groovy environment setup (download groovy | install groovy | configure groovy environment variables)](/img/99/bb05b6c48a9e70ca7ff77733d954b9.jpg)
[groovy] groovy environment setup (download groovy | install groovy | configure groovy environment variables)

Interview summary: This is a comprehensive & detailed Android interview guide
随机推荐
New interesting test applet source code_ Test available
UI自動化測試從此告別手動下載瀏覽器驅動
深度学习——LSTM基础
@Transactional 注解导致跨库查询失效的问题
官宣!第三届云原生编程挑战赛正式启动!
Redis之Jedis如何使用
Multimedia query
Resolved (sqlalchemy+pandas.read_sql) attributeerror: 'engine' object has no attribute 'execution_ options‘
线上故障突突突?如何紧急诊断、排查与恢复
[web Audit - source code disclosure] obtain source code methods and use tools
ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 1)
In MySQL Association query, the foreign key is null. What if the data cannot be found?
Basic function learning 02
Plasticscm enterprise crack
天干地支纪年法中为什么是60年一个轮回,而不是120年
Learning notes of raspberry pie 4B - IO communication (I2C)
25K 入职腾讯的那天,我特么哭了
[groovy] string (string type variable definition | character type variable definition)
[charging station]_ Secular wisdom_ Philosophical wisdom _
【PHP特性-变量覆盖】函数的使用不当、配置不当、代码逻辑漏洞