I got an error with pygame2exe which I cannot solve. I looked at the problem with the font, but could not solve it using this method.
C:\Users\Quentin\Documents\school\SDD\12\tictactoe\dist\tictactoemain1.exe\zipextimporter.py:82: RuntimeWarning: import display: No module named _view
(ImportError: No module named _view)
C:\Users\Quentin\Documents\school\SDD\12\tictactoe\dist\tictactoemain1.exe\zipextimporter.py:82: RuntimeWarning: import draw: No module named _view
(ImportError: No module named _view)
C:\Users\Quentin\Documents\school\SDD\12\tictactoe\dist\tictactoemain1.exe\zipextimporter.py:82: RuntimeWarning: import image: No module named _view
(ImportError: No module named _view)
C:\Users\Quentin\Documents\school\SDD\12\tictactoe\dist\tictactoemain1.exe\zipextimporter.py:82: RuntimeWarning: import pixelcopy: No module named _view
(ImportError: No module named _view)
C:\Users\Quentin\Documents\school\SDD\12\tictactoe\dist\tictactoemain1.exe\zipextimporter.py:82: RuntimeWarning: import transform: No module named _view
(ImportError: No module named _view)
This is the error that I encountered
my code
import py2exe
import random
import pygame
from pygame.locals import *
import sys
import time
from Tkinter import *
import time
pygame.init()
gameover = True
clock = pygame.time.Clock()
pygame.display.set_caption("Tic Tac Toe")
p1 = "Player 1"
p2 = "Player 2"
CurrentRounds = "1"
menunames = []
rowlist = []
columnlist = []
player1test = True
computerselect = "False"
boxselect = [["","",""],
["","",""],
["","",""]]
boxpos = [[[268,268],[268,430],[268,592]],
[[430,268],[430,430],[430,592]],
[[592,268],[592,430],[592,592]]]
boxXpos = 0
boxYpos = 0
playerturn = "PLAYER1"
"""all of the events for the feild
initialises the feild
tests if win
updates and draws feild ect"""
class MainEvent():
def __init__(self, x, y, rounds):
self.winner = False
self.player1score = 0
self.player2score = 0
self.CurrentRounds = int(rounds)
self.MainFont = pygame.font.Font("micross.ttf", 50)
self.Outline = pygame.Rect((x,y), (500,500))
self.Inline = pygame.Rect((x,y), (486,486))
TL = pygame.Rect((x,y), (160,160))
TC = pygame.Rect((x,y), (160,160))
TR = pygame.Rect((x,y), (160,160))
ML = pygame.Rect((x,y), (160,160))
MM = pygame.Rect((x,y), (160,160))
MR = pygame.Rect((x,y), (160,160))
BL = pygame.Rect((x,y), (160,160))
BM = pygame.Rect((x,y), (160,160))
BR = pygame.Rect((x,y), (160,160))
self.boxtotal = [[TL,TC,TR],
[ML,MM,MR],
[BL,BM,BR]]
self.Lable1 = self.MainFont.render(p1,1, (0,0,0))
self.Lable2 = self.MainFont.render(p2,1, (0,0,0))
self.Lable3 = self.MainFont.render(str(CurrentRounds),1, (0,0,0))
self.Lable4 = self.MainFont.render(str(self.player1score),1, (0,0,0))
self.Lable5 = self.MainFont.render(str(self.player2score),1, (0,0,0))
self.x = x
self.y = y
self.posaddx = 268
self.posaddy = 106
def Draw(self, mousex, mousey, l):
self.Outline.centerx = 430
self.Outline.centery = 430
self.Inline.centerx = 430
self.Inline.centery = 430
self.posaddx = 268
self.posaddy = 268
for row in self.boxtotal:
for i in row:
i.centerx = self.posaddx
i.centery = self.posaddy
self.posaddx += 162
self.posaddx = 268
self.posaddy += 162
self.posaddy += 268
screen.blit(self.Lable1, (75,20))
screen.blit(self.Lable2, (75,80))
screen.blit(self.Lable3, (500,20))
screen.blit(self.Lable4, (20,20))
screen.blit(self.Lable5, (20,80))
self.Outline.clamp_ip(screen.get_rect())
screen.fill((0,0,0),self.Outline)
self.Inline.clamp_ip(screen.get_rect())
screen.fill((255,255,255),self.Inline)
countXcolour = 0
countYcolour = 0
for row in self.boxtotal:
countXcolour = 0
for i in row:
if boxselect[countYcolour][countXcolour] == "PLAYER1":
i.clamp_ip(screen.get_rect())
screen.fill((255,0,0),i)
elif boxselect[countYcolour][countXcolour] == "PLAYER2":
i.clamp_ip(screen.get_rect())
screen.fill((0,0,255),i)
elif boxselect[countYcolour][countXcolour] == "Winner":
i.clamp_ip(screen.get_rect())
screen.fill((0,255,0),i)
else:
i.clamp_ip(screen.get_rect())
screen.fill((0,0,0),i)
countXcolour += 1
countYcolour += 1
def update(self, turn, boxcheck):
countx = 0
county = 0
self.Lable3 = self.MainFont.render(str(self.CurrentRounds),1, (0,0,0))
self.Lable4 = self.MainFont.render(str(self.player1score),1, (0,0,0))
self.Lable5 = self.MainFont.render(str(self.player2score),1, (0,0,0))
if turn == "PLAYER1":
self.Lable1 = self.MainFont.render(p1,1, (255,0,0))
self.Lable2 = self.MainFont.render(p2,1, (0,0,0))
else:
self.Lable2 = self.MainFont.render(p2,1, (0,0,255))
self.Lable1 = self.MainFont.render(p1,1, (0,0,0))
def win(self, boxcheck):
Tie = 0
Game = False
for row in boxselect:
for i in row:
if i == "":
Tie += 1
if Tie == 0:
Game = True
rowcount = 0
player1test_column1 = True
player2test_column1 = True
player1test_column2 = True
player2test_column2 = True
player1test_column3 = True
player2test_column3 = True
for row in boxselect:
if row[0] != "PLAYER1" and player1test_column1 == True:
player1test_column1 = False
if row[0] != "PLAYER2" and player2test_column1 == True:
player2test_column1 = False
if row[1] != "PLAYER1" and player1test_column2 == True:
player1test_column2 = False
if row[1] != "PLAYER2" and player2test_column2 == True:
player2test_column2 = False
if row[2] != "PLAYER1" and player1test_column3 == True:
player1test_column3 = False
if row[2] != "PLAYER2" and player2test_column3 == True:
player2test_column3 = False
player1test = True
player2test = True
for i in row:
if i != "PLAYER1" and player1test == True:
player1test = False
if i != "PLAYER2" and player2test == True:
player2test = False
if player1test == True:
Game = True
self.player1score += 1
for i in self.boxtotal[rowcount]:
i.clamp_ip(screen.get_rect())
screen.fill((0,255,0),i)
for i in range(len(boxselect[rowcount])):
boxselect[rowcount][i] = "Winner"
if player2test == True:
Game = True
self.player2score += 1
for i in self.boxtotal[rowcount]:
i.clamp_ip(screen.get_rect())
screen.fill((0,255,0),i)
for i in range(len(boxselect[rowcount])):
boxselect[rowcount][i] = "Winner"
rowcount += 1
if player1test_column1 == True:
for i in range(len(boxselect)):
boxselect[i][0] = "Winner"
Game = True
self.player1score += 1
if player1test_column2 == True:
for i in range(len(boxselect)):
boxselect[i][1] = "Winner"
Game = True
self.player1score += 1
if player1test_column3 == True:
for i in range(len(boxselect)):
boxselect[i][2] = "Winner"
Game = True
self.player1score += 1
if player2test_column1 == True:
for i in range(len(boxselect)):
boxselect[i][0] = "Winner"
Game = True
self.player2score += 1
if player2test_column2 == True:
for i in range(len(boxselect)):
boxselect[i][1] = "Winner"
Game = True
self.player2score += 1
if player2test_column3 == True:
for i in range(len(boxselect)):
boxselect[i][2] = "Winner"
Game = True
self.player2score += 1
if boxselect[0][0] == "PLAYER1" and boxselect[1][1] == "PLAYER1" and boxselect[2][2] == "PLAYER1":
boxselect[0][0] = "Winner"
boxselect[1][1] = "Winner"
boxselect[2][2] = "Winner"
self.player1score += 1
Game = True
if boxselect[0][2] == "PLAYER1" and boxselect[1][1] == "PLAYER1" and boxselect[2][0] == "PLAYER1":
boxselect[0][2] = "Winner"
boxselect[1][1] = "Winner"
boxselect[2][0] = "Winner"
self.player1score += 1
Game = True
if boxselect[0][0] == "PLAYER2" and boxselect[1][1] == "PLAYER2" and boxselect[2][2] == "PLAYER2":
boxselect[0][0] = "Winner"
boxselect[1][1] = "Winner"
boxselect[2][2] = "Winner"
self.player2score += 1
Game = True
if boxselect[0][2] == "PLAYER2" and boxselect[1][1] == "PLAYER2" and boxselect[2][0] == "PLAYER2":
boxselect[0][2] = "Winner"
boxselect[1][1] = "Winner"
boxselect[2][0] = "Winner"
self.player2score += 1
Game = True
if Game == True and self.CurrentRounds > 0:
self.CurrentRounds -= 1
for row in range(len(boxselect)):
for i in range(len(boxselect)):
boxselect[row][i] = ""
if self.CurrentRounds == 0 or self.CurrentRounds == "Game over":
self.CurrentRounds = "Game over"
print "game over"
sys.exit()
def details():
writen1 = str(t.get(0.0, END))
writen2 = str(t2.get(0.0, END))
comp = str(var.get())
Rounds = str(n.get())
filehandle = open("player names", "w")
filehandle.write(writen1)
filehandle.write(writen2)
filehandle.write(comp + "\n")
filehandle.write(Rounds)
filehandle.close
main.destroy()
main.quit()
""" All of the TK menu stuff is in here text boxes, checkbutton, scroll wheel and lables. the reason for using TK is because the pygame module does not have text boxes
all of the names are pretty self explanetory"""
main = Tk()
main.title("Tic Tac Toe")
Lframe = Frame(main)
Lframe.pack(side="left")
var = IntVar()
Checkbutton(Lframe,
text="Vs. computer",
variable=var,
).pack()
t = Text(main,
width = 40,
height = 1)
t.pack(side="top")
t2 = Text(main,
width = 40,
height = 1)
t2.pack(side="top")
l1 = Label(main, text="number of rounds").pack(side="left", anchor="w")
n = Spinbox(main,
from_=1,
to=25,
)
n.pack(side="left", anchor="e")
Button(Lframe,
text = "Run",
width = 15,
command=details,
).pack()
t.insert(INSERT, "Player 1")
t2.insert(INSERT, "Player 2")
main.mainloop()
"""end of all the TK menu stuff"""
filehandle = open("player names", "r")
for line in filehandle:
menunames.append(line)
filehandle.close
p1 = menunames[0]
p1 = p1[:-1]
p2 = menunames[1]
p2 = p2[:-1]
Vs = menunames[2]
Vs = Vs[:-1]
Round = menunames[3]
x = 250
y = 250
MainEventVar = MainEvent(250,250,Round)
name = []
keyreleased = True
event = pygame.event.poll()
screen = pygame.display.set_mode((700,700), 0, 32)
screen.fill((255,255,255), rect=None)
MainEventVar.update("PLAYER1",boxselect)
while True:
screen.fill((255,255,255))
clock.tick(144)
mx,my = pygame.mouse.get_pos()
l,c,r = pygame.mouse.get_pressed()
keys = pygame.key.get_pressed()
x = y
y += 1
MainEventVar.Draw(mx, my, l)
if Vs == "1":
if playerturn == "PLAYER2":
pos1 = random.randint(0,2)
pos2 = random.randint(0,2)
while boxselect[pos1][pos2] != "":
pos1 = random.randint(0,2)
pos2 = random.randint(0,2)
boxselect[pos1][pos2] = "PLAYER2"
playerturn = "PLAYER1"
MainEventVar.win(boxselect)
if l and gameover == True:
yPosTrue = 0
xPosTrue = 0
boxXpos = 0
boxYpos = 0
over = False
for row in boxpos:
boxXpos = 0
for i in row:
if mx in range(i[0]-81,i[0]+81) and my in range(i[1]-81,i[1]+81) and on == False:
over = True
yPosTrue = boxYpos
xPosTrue = boxXpos
on = True
boxXpos += 1
boxYpos += 1
if over == True and boxselect[xPosTrue][yPosTrue] == "":
boxselect[xPosTrue][yPosTrue] = playerturn
MainEventVar.win(boxselect)
if playerturn == "PLAYER1":
playerturn = "PLAYER2"
else:
playerturn = "PLAYER1"
else:
on = False
MainEventVar.update(playerturn,boxselect)
pygame.display.update()
if keys[pygame.K_ESCAPE]:
sys.exit()
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
I managed to create it using py2exe and it would start the tk section of code, but it would work when loading the pygame section. this is apparently a font-related problem from the error py2exe gives, but after some suggestions from other problems that people had, I still cannot solve it.