pygame

How to draw dynamic programming table in python

一笑奈何 提交于 2019-12-31 17:23:41
问题 What is a good way to draw a dynamic programming such as this one (with the path) in python? I have looked online and I see pygame but is that really the best option for this sort of technical drawing? One option might be to use matplotlib using something like import matplotlib.pylab as plt plt.figure() col_labels=['col1','col2','col3'] row_labels=['row1','row2','row3'] table_vals=[[11,12,13],[21,22,23],[31,32,33]] the_table = plt.table(cellText=table_vals, colWidths = [0.1]*3, rowLabels=row

Pygame安装教程

左心房为你撑大大i 提交于 2019-12-31 12:32:28
1、python --version 查看安装的Python版本,   pip --version 查看安装的pip版本,   升级pip命令: python -m pip install --upgrade pip   如果已经下载了安装文件就使用:pip install 文件名   如果没有下载就使用:python -m pip install --user 模块名,系统自动下载 2、如果没有安装pip,先安装pip。网址是:https://pypi.python.org/pypi/pip#downloads      下载第二个就行,解压后,运行setup.py。   现在打开cmd,查看pip安装版本,现在pip已经安装完成了。   cmd中输入pip list ,你会看到使用pip安装的所有包。  3、下载pygame: http://www.lfd.uci.edu/~gohlke/pythonlibs/#pygame   cp27代表python2.7版本,win32代表32位操作系统。我的是python3.7,系统是64位,所以我下载的是   pygame-1.9.4-cp37-cp37m-win_amd64.whl   下载的文件名后缀是whl,因此下一步就是安装能够运行whl文件的程序。 4、安装wheel ,进入cmd,输入命令:pip install

PyGame bogging down linux?

泪湿孤枕 提交于 2019-12-31 07:04:14
问题 When I run my pygame code it bogs down the system. PyGame becomes unresponsive and it slows down Ubuntu so much that I've had to force a shut down twice. I posted a very similar question here: Why is my basic PyGame module so slow? but I decided to rephrase it because when I asked the original question I wasn't aware of the full symptoms. 回答1: You should limit the fps, you can use clock.tick for that while true: for event in pygame.event.get(): #manage your events #update your sprites screen

Errno 13 Permission denied: 'file.mp3' Python

送分小仙女□ 提交于 2019-12-31 06:28:12
问题 I am getting an error when writing to an audio file. Basically, I am overwriting the data in the mp3 whenever my function gets called and then playing it. It works the first time through, but then gives me [Errno 13] Permission denied: 'file.mp3' then on. Here is the code: def speech(self, response): audio_file = "response.mp3" tts = gTTS(text=str(response), lang="en") tts.save(audio_file) pygame.mixer.init() pygame.mixer.music.load(audio_file) pygame.mixer.music.play() Error is on the tts

Errno 13 Permission denied: 'file.mp3' Python

天涯浪子 提交于 2019-12-31 06:26:29
问题 I am getting an error when writing to an audio file. Basically, I am overwriting the data in the mp3 whenever my function gets called and then playing it. It works the first time through, but then gives me [Errno 13] Permission denied: 'file.mp3' then on. Here is the code: def speech(self, response): audio_file = "response.mp3" tts = gTTS(text=str(response), lang="en") tts.save(audio_file) pygame.mixer.init() pygame.mixer.music.load(audio_file) pygame.mixer.music.play() Error is on the tts

Pygame using time.sleep to wait for x seconds not executing code above it

杀马特。学长 韩版系。学妹 提交于 2019-12-31 06:22:30
问题 I am trying to recreate Pong in pygame and have tried to change the color of the net to red or green, based on who scores. I am able to keep it red or green after someone scores, until a different person scores, however, I want to change the net color back to black after 3 seconds. I tried using time.sleep(3) but whenever I did it, the net will stay as black. ` elif pong.hitedge_right: game_net.color = (255,0,0) time.sleep(3) scoreboard.sc1 +=1 print(scoreboard.sc1) pong.centerx = int

Kivy :[CRITICAL] [App ] Unable to get a Window, abort

大兔子大兔子 提交于 2019-12-31 05:36:09
问题 I recently installed kivy in my Ubuntu 16.04 machine, and tried to create first application with it as given in the docs. But as soon as I tried running main.py , I got the following error: [INFO ] [Logger ] Record log in /home/yathartha/.kivy/logs/kivy_17-08-03_7.txt [INFO ] [Kivy ] v1.9.0 [INFO ] [Python ] v3.5.2 (default, Nov 17 2016, 17:05:23) [GCC 5.4.0 20160609] [INFO ] [Factory ] 173 symbols loaded [INFO ] [Image ] Providers: img_tex, img_dds, img_gif, img_sdl2, img_pil (img_ffpyplayer

fatal python error pygame parachute

早过忘川 提交于 2019-12-31 05:28:07
问题 I have written a small program in WindowsXP-python-pygame. It runs fine when I run it in the dos. Then, I tried to create a windows executable using py2exe. .exe was created without any issue. Initially on running the executable, I got a NotImplemented error which went away after I copied some dll files from pygame folder to the dist folder. Now I am getting a new error. It reads: "Fatal Python error: (pygame parachute) Segmentation Fault This application has requested the Runtime to

PyGame and Unicode - a neverending story

只愿长相守 提交于 2019-12-31 05:07:00
问题 What I do in my code: 1st I load a UTF-8 textfile (yes, double/triple/quadruple checked: it IS UTF-8) by using with codecs.open... def load_verbslist(folder, name, utf_encoding): fullname = os.path.join("daten", folder, name) if utf_encoding: with codecs.open(fullname, "r", "utf-8-sig") as name: lines = name.readlines() else: name = open(fullname, "r") lines = name.readlines() for x in range(0, len(lines)): lines[x] = lines[x].strip("\n") lines[x] = lines[x].strip("\r") return lines From that

How to blit an image, in python, inside the area of a specific image?

白昼怎懂夜的黑 提交于 2019-12-31 05:04:12
问题 I'm making a game and I need to blit my objects inside the area of a specific image. I don't want to need my surface to blit these images. Is it possible? (I'm using pygame) 回答1: It would be better in the future if you would explain what you are trying to do a bit better since it would give you more answers :) From what I have understood you want to blit an image onto another image: For this code to work the following premises are set: The folder which contains the program also contains the