有没有办法在 pygame 上显示 Excel 工作表?

发布于 2025-01-20 06:24:30 字数 593 浏览 0 评论 0原文

不太确定如何用这个话语,但是我在Excel中有一个信息数据库,一旦他们单击一个按钮,我就想将其显示到Pygame UI。任何人都知道是否可能,我该怎么做?

数据如下: excel data

我只设法实现了这一点:

MasterList = pd.read_csv(r'MasterList.csv')
def display_all():
ending = False
while not ending:
    display(MasterList)
    ending = True
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()            
    pygame.display.update()

但是它仅在端子中显示Excel纸,但不显示UI。

任何帮助将不胜感激!

Not quite sure how to phrase this, but I have a database of information in Excel that I want to display to the pygame UI once they click a button. Anyone know if it is even possible, and how do I go about doing it?

The data is something as follows: Excel Data

I've only managed to get this far:

MasterList = pd.read_csv(r'MasterList.csv')
def display_all():
ending = False
while not ending:
    display(MasterList)
    ending = True
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            pygame.quit()
            quit()            
    pygame.display.update()

But it only displays the excel sheet in the terminal but not the UI.

Any help is greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

书间行客 2025-01-27 06:24:30

如果您只需要显示它,您可以尝试将工作表转换为图像,然后将其加载到pygame中。
代码来自:https://blog. aspose.com/2021/05/28/convert-excel-to-image-in-python/

# load the Excel workbook
workbook = Workbook("Book1.xlsx")

# create image options
imgOptions = ImageOrPrintOptions()
imgOptions.setSaveFormat(SaveFormat.SVG)

# load the worksheet to be rendered
sheet = workbook.getWorksheets().get(0)

# create sheet render object
sr = SheetRender(sheet, imgOptions)

# convert sheet to PNG image
for j in range(0, sr.getPageCount()):
    sr.toImage(j, "WorksheetToImage-out%s" %(j) + ".png")

之后,使用 pygame.image.load() ,然后.blit() 它。

If you only need to display it, you can try converting the worksheet to an image and then loading it into pygame.
Code from: https://blog.aspose.com/2021/05/28/convert-excel-to-image-in-python/

# load the Excel workbook
workbook = Workbook("Book1.xlsx")

# create image options
imgOptions = ImageOrPrintOptions()
imgOptions.setSaveFormat(SaveFormat.SVG)

# load the worksheet to be rendered
sheet = workbook.getWorksheets().get(0)

# create sheet render object
sr = SheetRender(sheet, imgOptions)

# convert sheet to PNG image
for j in range(0, sr.getPageCount()):
    sr.toImage(j, "WorksheetToImage-out%s" %(j) + ".png")

After that, use pygame.image.load() and then .blit() it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文