我刚刚开始研究Pygames,并且在编程GUI时非常蠢,但是我正在尝试创建一个由窗口左侧的用户界面控制的模拟。也就是说,模拟和界面都在这里看到的同一个窗口:
我一直在网上查看很多类似的问题/例子,但它们都非常深入,我真的需要一些非常愚蠢的东西。也就是说,我想知道的是如何在一个窗口上创建两个显示,如上所示。我为它的“模拟”部分提取了一些代码,通常概述如下:
import pygame
import math
pygame.font.init()
clock = pygame.time.Clock()
font = pygame.font.SysFont("", 20)
pygame.init()
width = 1000
height = 600
main_s = pygame.display.set_mode((width, height))
running = True
while running:
clock.tick(60)
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
None
key = pygame.key.get_pressed()
对于“界面”组件,我计划使用Tkinter放入一个表单,并使用其中的输入来操作“模拟”。
我已经看到一些例子提到了一些关于多个场景和类的内容。我不知道这是不是我要找的是什么(因为无论出于什么原因他们从未显示过输出),但是由于上面复制的代码从未提及类或场景,我不知道如何将其合并。
因此,在我开始运行并使事情变得更加复杂之前,我认为简单地问一下:实现我需要的配置/接口的简单大纲是什么?
谢谢, 森
答案 0 :(得分:2)
最简单的方法就是创建两个单独的表面并将它们视为单独的屏幕。例如,如果您有一个800 x 600的窗口,则可以创建600 x 600图像和200 x 600图像。
像这样......
...
actual_screen = pygame.display.set_mode((800, 600))
simulation_screen = pygame.Surface((600, 600))
interface_screen = pygame.Surface((200, 600))
...
while running:
# ... game code that renders to each surface as though
# they are separate screens ...
actual_screen.blit(simulation_screen, (0, 0))
actual_screen.blit(interface_screen, (600, 0))
pygame.display.flip()
...