ZetCode PyQt4 tutorial First programs

简介: #!/usr/bin/python # -*- coding: utf-8 -*- """ ZetCode PyQt4 tutorial In this example, we create a simple window in PyQt4.
#!/usr/bin/python
# -*- coding: utf-8 -*-

"""
ZetCode PyQt4 tutorial 

In this example, we create a simple
window in PyQt4.

author: Jan Bodnar
website: zetcode.com 
last edited: October 2011
"""
# Here we provide the necessary imports. The basic GUI widgets are located in the QtGui module.
import sys
from PyQt4 import QtGui


def main():
    
    # Every PyQt4 application must create an application object. The application object is located in the QtGui module. The sys.argv parameter is a list of arguments from the command line. Python scripts can be run from the shell. It is a way how we can control the startup of our scripts.
    app = QtGui.QApplication(sys.argv)

    # The QtGui.QWidget widget is the base class of all user interface objects in PyQt4. We provide the default constructor for QtGui.QWidget. The default constructor has no parent. A widget with no parent is called a window.
    w = QtGui.QWidget()
    # The resize() method resizes the widget. It is 250px wide and 150px high.
    w.resize(250, 150)
    # The move() method moves the widget to a position on the screen at x=300 and y=300 coordinates.
    w.move(300, 300)
    # Here we set the title for our window. The title is shown in the titlebar.
    w.setWindowTitle('Simple')
    # The show() method displays the widget on the screen. A widget is first created in memory and later shown on the screen.
    w.show()
    
    # Finally, we enter the mainloop of the application. The event handling starts from this point. The mainloop receives events from the window system and dispatches them to the application widgets. The mainloop ends if we call the exit() method or the main widget is destroyed. The sys.exit() method ensures a clean exit. The environment will be informed how the application ended.
    # The exec_() method has an underscore. It is because the exec is a Python keyword. And thus, exec_() was used instead.
    sys.exit(app.exec_())


# When the Python interpreter reads a source file, it executes all of the code found in it. Before executing the code, it will define a few special variables. For example, if the python interpreter is running that module (the source file) as the main program, it sets the special __name__ variable to have a value "__main__". If this file is being imported from another module, __name__ will be set to the module's name.
if __name__ == '__main__':
    main()

 

目录
相关文章
|
7月前
|
存储 消息中间件 前端开发
PHP后端与uni-app前端协同的校园圈子系统:校园社交场景的跨端开发实践
校园圈子系统校园论坛小程序采用uni-app前端框架,支持多端运行,结合PHP后端(如ThinkPHP/Laravel),实现用户认证、社交关系管理、动态发布与实时聊天功能。前端通过组件化开发和uni.request与后端交互,后端提供RESTful API处理业务逻辑并存储数据于MySQL。同时引入Redis缓存热点数据,RabbitMQ处理异步任务,优化系统性能。核心功能包括JWT身份验证、好友系统、WebSocket实时聊天及活动管理,确保高效稳定的用户体验。
434 4
PHP后端与uni-app前端协同的校园圈子系统:校园社交场景的跨端开发实践
|
7月前
|
Java Linux
自定义linux脚本用于快速jar包启动、停止、重启
自定义linux脚本用于快速jar包启动、停止、重启
332 29
|
7月前
|
人工智能 JavaScript 前端开发
【CodeBuddy】三分钟开发一个实用小功能之:3D旋转相册
通过CodeBuddy,用自然语言描述需求即可快速实现炫酷3D相册。本文展示了从零开始构建一个可旋转的6面3D相册的过程:AI自动生成HTML骨架、CSS样式及JS交互逻辑,甚至优化性能与修复问题。无需代码基础,仅需明确需求,AI便能将想法变为现实。最终效果支持鼠标拖拽旋转、触摸操作及图片预览放大,完整代码附于文末。这一体验凸显了AI编程工具在降低技术门槛、提升开发效率方面的巨大潜力,让开发者专注于创意本身。
205 2
【CodeBuddy】三分钟开发一个实用小功能之:3D旋转相册
|
数据采集 自然语言处理 算法
使用Python进行简单文本分类
本文将通过Python编程语言介绍如何实现简单的文本分类,包括数据预处理、特征提取和模型训练等步骤。我们将使用scikit-learn库中的朴素贝叶斯分类器作为示例,展示如何训练模型并进行预测。通过本文,你将学会如何使用Python进行文本分类任务,并了解其背后的基本原理。
|
10月前
|
存储 缓存 小程序
微信小程序数据缓存与本地存储:优化用户体验
本文深入探讨微信小程序的数据缓存与本地存储,介绍其意义、机制及应用场景。通过合理使用内存和本地缓存,可减少网络请求、提升加载速度和用户体验。文中详细讲解了常用缓存API的使用方法,并通过一个新闻列表案例展示了缓存的实际应用。最后提醒开发者注意缓存大小限制、时效性和清理,以确保最佳性能。
|
7月前
|
人工智能 运维 前端开发
【CodeBuddy】三分钟开发一个实用小功能之:九宫格图片切割&生成器
这是一篇关于借助AI编程助手`CodeBuddy`开发九宫格图片处理工具的实践分享。该工具支持图片切割与合成两种模式,具备良好的用户界面和便捷的下载功能,适用于社交媒体、电商设计等场景。通过详细描述需求,`CodeBuddy`快速生成了完整的解决方案,包括HTML、CSS和JavaScript代码。文章还探讨了代码优化方向,如提升用户体验和性能,并展示了实际操作界面与效果。此项目不仅体现了AI编程的高效性,也为开发者提供了创新思路。
177 0
【CodeBuddy】三分钟开发一个实用小功能之:九宫格图片切割&生成器
|
缓存 开发框架 Java
如何优化Spring Boot应用的启动时间?
如何优化Spring Boot应用的启动时间?
|
物联网 5G SDN
|
Java 关系型数据库 MySQL
errorCode 1045, state 28000错误详解即解决方法
errorCode 1045, state 28000错误详解即解决方法
2766 0
errorCode 1045, state 28000错误详解即解决方法