Pycharm Qt Designer的使用示例

Pycharm Qt Designer的使用示例PycharmQtDes 的使用关于 QtDesigner 各组件的介绍可参考 QtDesigner 常用部件介绍 里面介绍了 QtDesigner 各部件的名字 QtDesigner 的使用很简单 直接根据自己所需把各部件拖入框内 更改各组件名称 大小 位置等 例如 去除文件夹中模糊的图片但是你会发现转换为 py 文件运行后并没有出现设计好的界面 这时需要在该文件夹下重新建立一个

Pycharm Qt Designer的使用示例

from PyQt5 import QtWidgets from remove import Ui_Form #导入remove.py生成的类,Ui_Form为remove.py中类的名字 class mywindow(QtWidgets.QWidget, Ui_Form): def __init__ (self): #析构函数 super(mywindow, self).__init__() self.setupUi(self) if __name__=="__main__": import sys app=QtWidgets.QApplication(sys.argv) ui = mywindow() ui.show() sys.exit(app.exec_()) 
#!/usr/bin/env python # -*- coding:utf-8 -*- # author: feifan time:2019/5/21 import sys import cv2 import os from PyQt5 import QtWidgets from PyQt5.QtWidgets import QMainWindow, QApplication, QFileDialog from PyQt5.QtGui import * from remove import Ui_Form class mywindow(QtWidgets.QWidget, Ui_Form): def __init__(self): super(mywindow, self).__init__() self.setupUi(self) self.setWindowTitle('图片筛选') self.InputButton.clicked.connect(self.openFile) #点击按钮InputButton时调用openFile函数 self.OutputButton.clicked.connect(self.saveFile) # 点击按钮OutputButton时调用saveFile函数 self.beginButton.clicked.connect(self.beginrun) # 点击按钮beginButton时调用beginrun函数 self.closeButton.clicked.connect(self.close) # 点击按钮closeButton时调用内置方法关闭 def makedir(path): #新建文件夹 if not os.path.exists(path): os.mkdir(path) def openFile(self): openfile_path = QFileDialog.getExistingDirectory(self, "请选择输入图片的路径", "/") #文件夹绝对路径 self.Inputtext.setText(openfile_path) #将文件夹路径显示在Inputtext文本框中 def saveFile(self): savefile_path = QFileDialog.getExistingDirectory(self, "请选择输出图片的路径", '/') #文件夹绝对路径 self.Outputtext.setText(savefile_path) #将文件夹路径显示在Outputtext文本框中 def beginrun(self): ImgPath = self.Inputtext.text() #获取Inputtext中的内容即文件夹路径名 SavePath =self.Outputtext.text() #makedir(SavePath)#如果没有该文件夹可新建 THRESHOLD = 550.0 #像素阈值 imagelist = os.listdir(ImgPath) # 返回指定的文件夹包含的文件或文件夹的名字的列表。 for imagee in imagelist: imgfile = ImgPath + '/' + imagee image = cv2.imread(imgfile); img2gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) imageVar = cv2.Laplacian(img2gray, cv2.CV_64F).var() # 像素值 if imageVar < THRESHOLD: continue savefile = SavePath + '/' + imagee cv2.imwrite(savefile, image) if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) ui = mywindow() ui.show() sys.exit(app.exec_()) 

注意:在使用Qt Desigher时应注意各组件相对应的方法,比如刚开始Inputtext和Outputtext处我用的是Text Edit组件,结果Text Edit组件没有相应的text()方法来获取文本内容,一直显示“进程已结束,退出代码- (0xC0000409)”为此我找了很久的错误。。。。最后把Text Edit组件换成了Line Edit组件才能正常运行。所以你输入函数时一定要仔细看Pycharm给出的提示函数中是否有该函数!

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/173712.html原文链接:https://javaforall.net

(0)
上一篇 2026年3月27日 上午8:11
下一篇 2026年3月27日 上午8:11


相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号