Home > other >  [for] use pyinstaller generated exe running without error black window and flash back
[for] use pyinstaller generated exe running without error black window and flash back

Time:11-03

With only two py files (in pycharm normal operation), generated exe running tips for

Application interface for the black window:


The main. Py
 import pygame 
The from pygame. Locals import *
The from GameMap import *

The class Button () :
Def __init__ (self, screen, text, x, y, color, enable) :
The self. The screen=screen
The self. The width=BUTTON_WIDTH
The self. The height=BUTTON_HEIGHT
Self. Button_color=color
Self. Text_color=(255, 255, 255)
The self. The enable=enable
The self. The font=pygame. The font. SysFont (None, BUTTON_HEIGHT * 2//3)

The self. The rect=pygame. The rect (0, 0, the self. The width, the self. Height)
The self. The rect. Topleft=(x, y)
The self. The text=text
Self. Init_msg ()

Def init_msg (self) :
If the self. The enable:
Self. Msg_image=self. The font. Render (self. The text, the True self. Text_color, self. Button_color [0])
The else:
Self. Msg_image=self. The font. Render (self. The text, the True self. Text_color, self. Button_color [1])
Self. Msg_image_rect=self. Msg_image. Get_rect ()
Self. Msg_image_rect. Center=self. The rect. Center

Def the draw (self) :
If the self. The enable:
The self. The screen. The fill (self button_color [0], the self. The rect)
The else:
The self. The screen. The fill (self button_color [1], the self. The rect)
The self. The screen. The blit (self. Msg_image, self. Msg_image_rect)


The class StartButton (Button) :
Def __init__ (self, screen, text, x, y) :
Super () __init__ (screen, text, x, y, [(26, 173, 25), (158, 217, 157) ", True)

Def click (self, game) :
If the self. The enable:
Game. The start ()
Game. The winner=None
Self. Msg_image=self. The font. Render (self. The text, the True self. Text_color, self. Button_color [1])
The self. The enable=False
Return True
Return False

Def unclick (self) :
If not the self. The enable:
Self. Msg_image=self. The font. Render (self. The text, the True self. Text_color, self. Button_color [0])
The self. The enable=True

The class GiveupButton (Button) :
Def __init__ (self, screen, text, x, y) :
Super () __init__ (screen, text, x, y, [(230, 67, 64), (236, 139, 137)], False)

Def click (self, game) :
If the self. The enable:
Game. Is_play=False
If game. The winner is None:
Game. The winner=game. Map. ReverseTurn (game. The player)
Self. Msg_image=self. The font. Render (self. The text, the True self. Text_color, self. Button_color [1])
The self. The enable=False
Return True
Return False

Def unclick (self) :
If not the self. The enable:
Self. Msg_image=self. The font. Render (self. The text, the True self. Text_color, self. Button_color [0])
The self. The enable=True

The class Game () :
Def __init__ (self, caption) :
Pygame. The init ()
The self. The screen=pygame. Display. Set_mode ([SCREEN_WIDTH and SCREEN_HEIGHT])
Pygame. Display. Set_caption (caption)
The self. The clock=pygame. Time. Clock ()
Self. Buttons=[]
Self. Buttons. Append (StartButton (self) screen, 'Start', MAP_WIDTH + 30, 15))
Self. Buttons. Append (GiveupButton (self) screen, 'Giveup, MAP_WIDTH + 30, BUTTON_HEIGHT + 45))
Self. Is_play=False

The self. The map=map (CHESS_LEN CHESS_LEN)
The self. The player=MAP_ENTRY_TYPE. MAP_PLAYER_ONE
The self. The action=None
The self. The winner=None

Def start (self) :
Self. Is_play=True
The self. The player=MAP_ENTRY_TYPE. MAP_PLAYER_ONE
The self. The map. The reset ()

Def play (self) :
The self. The clock. Tick (60)

Light_yellow=(247, 238, 214)
Pygame. The draw. The rect (self) screen, light_yellow, pygame. The rect (0, 0, MAP_WIDTH SCREEN_HEIGHT))
Pygame. The draw. The rect (self. Screen (255, 255, 255), pygame. The rect (MAP_WIDTH, 0, INFO_WIDTH, SCREEN_HEIGHT))

For the button in the self. Buttons:
Button. The draw ()

If self. Is_play and not self. IsOver () :
If the self. The action is not None:
Self. CheckClick (self. The action [0], the self. The action [1])
The self. The action=None

If not the self. IsOver () :
Self. ChangeMouseShow ()

If self. IsOver () :
Self. ShowWinner ()

The self. The map. The drawBackground (self) screen)
The self. The map. DrawChess (self) screen)


Def changeMouseShow (self) :
Map_x, map_y=pygame. Mouse. Get_pos ()
X, y=self. Map. MapPosToIndex (map_x, map_y)
If the self. The map. IsInMap (map_x, map_y) and the self. The map. The isEmpty (x, y) :
Pygame. Mouse. Set_visible (False)
Light_red=(213, 90, 107)
Pos, the radius=(map_x, map_y), CHESS_RADIUS
Pygame. The draw. Circle (radius, the self. The screen, light_red, pos,)
The else:
Pygame. Mouse. Set_visible (True)

Def checkClick (self, x, y, isAI=False) :
The self. The map. Click (x, y, the self. The player)
The self. The player=self. Map. ReverseTurn (self. Player)

Def mouseClick (self, map_x, map_y) :
If self. Is_play and self. Map. IsInMap (map_x, map_y) and not self. IsOver () :
X, y=self. Map. MapPosToIndex (map_x, map_y)
If the self. The map. IsEmpty (x, y) :
Self. Action=(x, y)

Def isOver (self) :
Return the self. The winner is not None

Def showWinner (self) :
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related