欧克,连接成功!!!
# server默认为127.0.0.1,如果打开了TCP动态端口的需要加上端口号,如‘127.0.0.1:1433‘ # user默认为sa # password为自己设置的密码 # database为数据库名字 server = ‘127.0.0.1‘ user = "sa" password = "123456" database = "pubs" conn = pymssql.connect(server, user, password, database) # 可简化为conn = pymssql.connect(host=‘localhost‘, user=‘sa‘, password=‘123456‘, database=‘pubs‘) cursor = conn.cursor() cursor.execute(‘SELECT * FROM titles‘) print( cursor.fetchall() ) # 如果用pandas读取数据库 import pymssql import pandas as pd conn = pymssql.connect(‘IP地址‘,‘账号‘,‘密码‘,‘数据库‘) sql_1 = "SELECT Id,creat_time from 表名" #利用pandas直接获取数据" data = pd.read_sql(sql_1, conn) conn.close() print(data) import pygame pygame.init() screen=pygame.display.set_mode((600,800)) pygame.display.set_caption("这是一个飞机游戏") icon=pygame.image.load(r‘E:\2dsrc\src\img\hero1.png‘) bg=pygame.image.load(r‘E:\2dsrc\src\img\bg.png‘) hero=pygame.image.load(r‘E:\2dsrc\src\img\hero1.png‘) pygame.display.set_icon(icon) heroX=250 #x坐标 #游戏主循环 while True: #事件遍历 for event in pygame.event.get(): if event.type==pygame.QUIT: exit() heroX=heroX-3 screen.blit(bg,(0,0)) screen.blit(hero,(heroX,680)) pygame.display.update() import pygame pygame.init() screen=pygame.display.set_mode((600,800)) pygame.display.set_caption("这是一个飞机游戏") icon=pygame.image.load(r‘E:\2dsrc\src\img\hero1.png‘) hero=pygame.image.load(r‘E:\2dsrc\src\img\hero1.png‘) bg=pygame.image.load(r‘E:\2dsrc\src\img\bg.png‘) pygame.display.set_icon(icon) #游戏主循环 while True: #事件遍历 for event in pygame.event.get(): if event.type==pygame.QUIT: exit() if event.type==pygame.KEYDOWN: if event.key == pygame.K_RIGHT: print(‘→‘) elif event.key == pygame.K_LEFT: print(‘←‘) elif event.key == pygame.K_UP: print(‘↑‘) elif event.key == pygame.K_DOWN: print(‘↓‘) screen.blit(bg,(0,0)) screen.blit(hero,(heroX,680)) pygame.display.update()o