PyQt 第一个GUI应用例子

第一个GUI应用例子

1.使用Python 的GUI设计工具Qt Designer(QT设计师)创建用户界面
2.依据功能需求布局小部件(widgets)
3.使用IDE设计工具Eric6导入UI设计文件(.ui编译成.py)
4.对界面编辑生成的py文件进行应用改写


  1. 使用QT设计师创建如下界面
    QT Designer 创建的界面
  2. 小部件功能介绍
    1. Label widget(Label 部件)常用功能介绍
      1. setText() : This method assigns text to the Label widget
      2. setNum() : This method assigns an integer or double value to the Label widget
      3. clear() : This method clears text from the Label widget
    2. Line Edit widget 常用功能介绍
      • maxLength() : This method is used to specify the maximum length of text that can be entered in the Line Edit widget.
      • setText() : This method is used for assigning text to the Line Edit widget.
      • text() : This method accesses the text entered in the Line Edit widget.
      • clear() : This method clears or deletes the complete content of the Line Editwidget.
      • setFocus() : This method positions the cursor on the specified Line Editwidget.
    3. Push Buttonwidget 常用功能介绍
      1. setText() : This method is used to assign text to the push button
      2. setIcon() : This method is used to assign an icon to the push button
  3. 使用IDE工具导入UI设计文件
    Eric6 UI编译文件
    生成的py文件
  4. 编写应用程序
class MyForm(QDialog):
	def __init__(self):
		super().__init__()
		self.ui = Ui_Dialog()
		self.ui.setupUi(self)
		self.ui.pushButton.clicked.connect(self.dispmessage)
		self.show()
	def dispmessage(self):
		self.ui.label_2.setText("Hello "+self.ui.textEdit.toPlainText())
		
if __name__=="__main__":
	app = QApplication(sys.argv)
	w = MyForm()
	w.show()
	sys.exit(app.exec_())
	
  1. 运行py文件进行功能验证
    程序运行

在这里插入图片描述

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值