-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
42 lines (33 loc) · 1 KB
/
main.py
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
41
42
import pygame
import tkinter as tk
from tkinter import filedialog
# 初始化Pygame
pygame.init()
# 设置窗口大小
screen_width = 800
screen_height = 600
screen = pygame.display.set_mode((screen_width, screen_height))
# 设置窗口标题
pygame.display.set_caption("Upload Image")
def upload_image():
root = tk.Tk()
root.withdraw() # 隐藏tkinter窗口
# 打开文件对话框选择图片
file_path = filedialog.askopenfilename()
# 加载选定的图片
if file_path:
image = pygame.image.load(file_path)
image_rect = image.get_rect(center=(screen_width // 2, screen_height // 2))
screen.blit(image, image_rect)
pygame.display.flip()
# 主循环
running = True
while running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
elif event.type == pygame.MOUSEBUTTONDOWN:
if event.button == 1: # 左键点击
upload_image()
pygame.display.update()
pygame.quit()