-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimgui_test.py
More file actions
40 lines (30 loc) · 1023 Bytes
/
Copy pathimgui_test.py
File metadata and controls
40 lines (30 loc) · 1023 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pygame
import imgui
from imgui.integrations.pygame import PygameRenderer
def main():
pygame.init()
size = 800, 600
screen = pygame.display.set_mode(size, pygame.DOUBLEBUF | pygame.OPENGL)
imgui.create_context()
renderer = PygameRenderer()
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
return
renderer.process_event(event)
# 更新DisplaySize为当前窗口大小
width, height = screen.get_size()
imgui.get_io().display_size = width, height
imgui.new_frame()
# 这里添加你的ImGui绘制代码
# 创建一个简单的窗口
if imgui.begin("Demo Window"):
imgui.text("Hello, ImGui!")
if imgui.button("Click Me"):
print("Button Clicked")
imgui.end()
imgui.render()
renderer.render(imgui.get_draw_data())
pygame.display.flip()
if __name__ == "__main__":
main()