pyqt5按鈕事件開啟檔案

2021-08-20 08:46:39 字數 977 閱讀 7298

self.pushbutton.clicked.connect(self.btn1_click)#設定繫結事件
def btn1_click

(self

):

filename,_

=qfiledialog.

getopenfilename

(qwidget(),

'open'

,r"e:\images1"

)

#開啟檔案或者如下:getopenfilename第乙個引數要求是qwidget物件
#filename,_=qfiledialog.getopenfilename(none

,'open',r"e:\images1",' ')

img=

qimage()

img.load(filename)

#更改大小,適應graphicsview視窗大小
img=img.scaled(self.graphicsview.width(),self.graphicsview.height())
#乙個問題是:img=

img.

scaled

(width=

self

.graphicsview.

width

(),height=

self

.graphicsview.

height

())這樣

#會出錯,不知道什麼原因

scene

=qgraphicsscene

() scene.

addpixmap

(qpixmap

().fromimage

(img))

self

.graphicsview.

setscene

(scene)

PyQt5 讀取檔案

本文 usr bin env python coding utf 8 import sys from pyqt5.qtgui import qfont class main qmainwindow def init self super main,self init 視窗標題 self.setwin...

pyqt5切換python版本 pyqt5介面切換

主要的思路就是建立兩個frame 如果有兩個以上同理 使用setvisible 函式顯示或者隱藏frame 引數是bool值 import sys from pyqt5.qtwidgets import from pyqt5.qtcore import from pyqt5.qtgui import...

PyQt5 點不著的按鈕

1 import sys2 import typing34 from pyqt5 import qtwidgets,qtgui,qtcore 5import random67 class mywindow qtwidgets.qwidget 8def init self,args,kwargs 91...