当前位置:网站首页>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 :
边栏推荐
- Yuancosmic ecological panorama [2022 latest]
- 我就一写代码的,王总整天和我谈格局...
- Kubernetes - identity and authority authentication
- 程序员的视力怎么样? | 每日趣闻
- Clickhouse同步mysql(基于物化引擎)
- [groovy] string (string type variable definition | character type variable definition)
- How to use jedis of redis
- Soul 3: what is interface testing, how to play interface testing, and how to play interface automation testing?
- Nmap user manual learning records
- The new project Galaxy token just announced by coinlist is gal
猜你喜欢
Learning notes of raspberry pie 4B - IO communication (I2C)
MindFusion.Virtual Keyboard for WPF
Use of vscode software
线上故障突突突?如何紧急诊断、排查与恢复
函数基础学习02
UE4 DMX和grandMA2 onPC 3.1.2.5的操作流程
An elegant program for Euclid‘s algorithm
51 independent key basic experiment
[web Audit - source code disclosure] obtain source code methods and use tools
[learning notes] month end operation -gr/ir reorganization
随机推荐
EasyCVR平台出现WebRTC协议视频播放不了是什么原因?
provide/inject
Blue Bridge Cup single chip microcomputer -- PWM pulse width modulation
glibc strlen 实现方式分析
Easy processing of ten-year futures and stock market data -- Application of tdengine in Tongxinyuan fund
ABP vNext microservice architecture detailed tutorial - distributed permission framework (Part 2)
Clickhouse同步mysql(基于物化引擎)
深度学习——LSTM基础
[PHP features - variable coverage] improper use, improper configuration and code logic vulnerability of the function
为什么百度、阿里这些大厂宁愿花25K招聘应届生,也不愿涨薪5K留住老员工?
Installation of postman and postman interceptor
speed or tempo in classical music
Basic knowledge of tuples
Basic function learning 02
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?
The new project Galaxy token just announced by coinlist is gal
This article takes you to understand the relationship between the past and present of Bi and the digital transformation of enterprises
Timing manager based on C #
It took two nights to get Wu Enda's machine learning course certificate from Stanford University
Flex flexible layout