回答編集履歴
1
追記・おまけの追加
answer
CHANGED
@@ -7,4 +7,49 @@
|
|
7
7
|
sys.exit() #システム終了
|
8
8
|
```
|
9
9
|
これを入れると割り込みができます。
|
10
|
-
これでもできない場合はまた教えてください。
|
10
|
+
これでもできない場合はまた教えてください。(ファイル名等は適切に置き換えてください)
|
11
|
+
|
12
|
+
## 追記
|
13
|
+
|
14
|
+
以下のプログラム(最小プログラム)実行してみてください(以下のサイトを参考)
|
15
|
+
[https://shizenkarasuzon.hatenablog.com/entry/2019/02/23/151418](https://shizenkarasuzon.hatenablog.com/entry/2019/02/23/151418)
|
16
|
+
```python
|
17
|
+
from pygame.locals import *
|
18
|
+
import pygame
|
19
|
+
import sys
|
20
|
+
|
21
|
+
def main():
|
22
|
+
pygame.init() # Pygameを初期化
|
23
|
+
screen = pygame.display.set_mode((400, 330)) # 画面を作成
|
24
|
+
pygame.display.set_caption("Pygame sample app") # タイトルを作成
|
25
|
+
|
26
|
+
running = True
|
27
|
+
#メインループ
|
28
|
+
while running:
|
29
|
+
screen.fill((0,0,0)) #画面を黒で塗りつぶす
|
30
|
+
|
31
|
+
# 画像を描画
|
32
|
+
#--------------- 1.画像を読み込む --------------------------
|
33
|
+
|
34
|
+
#一部の色を透明にする
|
35
|
+
img = pygame.image.load("test.jpg").convert()
|
36
|
+
colorkey = img.get_at((0,0))
|
37
|
+
img.set_colorkey(colorkey, RLEACCEL)
|
38
|
+
|
39
|
+
#--------------- 2.画像を表示 --------------------------
|
40
|
+
screen.blit(img, (0,0))
|
41
|
+
|
42
|
+
pygame.display.update() #描画処理を実行
|
43
|
+
for event in pygame.event.get():
|
44
|
+
if event.type == QUIT: # 終了イベント
|
45
|
+
running = False
|
46
|
+
pygame.quit() #pygameのウィンドウを閉じる
|
47
|
+
sys.exit() #システム終了
|
48
|
+
|
49
|
+
if __name__=="__main__":
|
50
|
+
main()
|
51
|
+
```
|
52
|
+
|
53
|
+
## おまけ
|
54
|
+
ボタン等の割り込み(イベント処理)は`for event in pygame.event.get()`内で行います。具体的な使い方等はpygame docsのkeyというところにあるのですが、(日本語翻訳版あり)こちらのサイトがわかりやすいかもです。
|
55
|
+
[https://sodocumentation.net/ja/pygame/topic/5110/%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E5%87%A6%E7%90%86](https://sodocumentation.net/ja/pygame/topic/5110/%E3%82%A4%E3%83%99%E3%83%B3%E3%83%88%E5%87%A6%E7%90%86)
|