我的目标是创建一个类似于http://i49.tinypic.com/f39hxv.png的网格,其中每个数字表示在每个正方形中找到的“准备工作薄片”的数量(参见下面的数据片段)
目前的代码如下:
import csv
import os
import pygame
# the functions for display
def disp(phrase,loc,screen): # function to display phrase at loc on surface.
s = font.render(phrase, True, (255,255,255))
screen.blit(s, loc) #
def text_display_csv(filename,surface):
'''Display .csv file contents on surface'''
f = csv.reader(open("Flint catalogue v1.7 4 Feb 13 2013.csv")) # open the csv file in one line!
for row in f:
y = f.line_num # assign y as Row no.
for x,item in enumerate(row): # Get column number(x) and item
disp(item, (64*x+10,64*y+10), surface) # display item
pygame.init()
pygame.font.init()
font = pygame.font.SysFont("Courier",10) # font initialisation
screen = pygame.display.set_mode((1200,1200))
filename = 'the .csv file'
text_display_csv(filename,screen) # text is displayed
pygame.display.update() # screen updated
# Main loop, does nothing! :)
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
pygame.quit()
break
if not running:
break
我希望网格看起来有点像这样(但我的问题是将数据库中的数据放入此数组):
^{pr2}$数据如下:
http://tinypic.com/view.php?pic=2rdgn02&s=6
所以总结一下。我希望不同的'分类'(见数据)显示在网格中,就像图片在开始。在
谢谢你的帮助
汤姆
这里有一些代码,
这是您的代码,最多10个字符(注释和删除除外),但会导致大的更改。在
更新1 好吧,我明白了。 所以,你想用P来显示网格号的数据。。。在
这也是密码。把
^{pr2}$text_display_csv
改成这个这里发生了什么:
.csv
S
列的项目,S
处的值是一个数字,则获取它的整数值。然后将信息以
S : P
的形式添加到字典中,其中S
是整数P
列P
处的字符串/值。在现在唯一的问题是数字必须从零开始。
为了克服这个问题,只需添加
以前
你的网格线可以用
pygame.draw.line
绘制,你可以搞清楚。在相关问题 更多 >
编程相关推荐