1.windows、linux,mac 安装python3
2.PC系统安装pygame, 指令:pip install pygame
3. 保存如下文件: test_game.py
4.PC上运行 python test_game.py
import pygame# 初始化Pygame
pygame.init()# 创建游戏窗口
window = pygame.display.set_mode((800, 600))
pygame.display.set_caption("Pygame测试")font = pygame.font.SysFont("Arial", 36)# 游戏循环
running = True
count = 0
index = 0
while running:for event in pygame.event.get():if event.type == pygame.QUIT:running = False# 绘制背景count+=1if(count>1000):index = (index+1)%3count = 0if(index==0):window.fill((255,0,0))if(index==1):window.fill((0,255,0))if(index==2):window.fill((0,0,255)) print("loop_count=",count)text = font.render('hello pygame:'+str(count), True, (0, 0, 0), (255, 255, 255))window.blit(text, (0, 0))# 刷新窗口pygame.display.update()# 退出游戏
pygame.quit()
print('=====pygame is quit!=====')
5.安装 pip3 install PyQt5==5.15.2
6. 保存如下文件[可用qtcreator辅助布局]: test_qt5.py
7.PC上运行 python test_qt5.py
import sys
from PyQt5.QtWidgets import QApplication, QWidget,QPushButtondef btn1_clicked():print("button_1 clicked!")def btn2_clicked():print("button_2 clicked!")if __name__ == "__main__":# 创建QApplication类的实例,并传入命令行参数app = QApplication(sys.argv)# 创建QWidget类的实例,相当于创建一个窗口w = QWidget()# 调整窗口的大小(宽,高)w.resize(320, 240)# 设置widget窗口背景颜色w.setStyleSheet("background-color:#00ee66;")# 移动窗口(显示的相对位置,左,上)w.move(100, 200)# 设置窗口的标题w.setWindowTitle("pyqt5 title")#创建按键btn1 = QPushButton("Fist_Button", w)btn1.setToolTip("this Btn1 tips") #button tips textbtn1.move(20, 50)btn1.clicked.connect(btn1_clicked)btn2 = QPushButton("Second_Button", w)btn2.setToolTip("this Btn2 tips") #button tips textbtn2.move(120, 50) btn2.clicked.connect(btn2_clicked)# 显示窗口w.show()# 进入循环的主循环,并通过exit函数确保主循环安全结束sys.exit(app.exec_())