Дурацкая ошибка кодировки
в очередной раз вылезает ошибка
UnicodeDecodeError: 'charmap' codec can't decode byte 0x98 in position 747: character maps to <undefined>
и я не знаю как её побороть. После перезагрузки IDE питона код запускается но работает не так как надо( Надеюсь на помощь. Вот сам код:
python
# -*- coding: utf-8 -*-
import time
import sys
import random
from PyQt5 import QtCore, QtGui, QtWidgets
import pygame
from pygame.locals import *
pygame.init()
# Настройка текста
# Назначение цветов
BLACK = (0, 0, 0)
global WHITE
WHITE = (255, 255, 255)
global mainClock
mainClock = pygame.time.Clock()
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
# Настройка окна
global windowSurface
windowSurface = pygame.display.set_mode((1000, 1000), 0, 32)
pygame.display.set_caption(u'Привет, мир!')
global basicFont
basicFont = pygame.font.SysFont(None, 48)
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(u"Игра")
Form.resize(589, 479)
Form.setStyleSheet("QLabel{\n"
"background-color: white;\n"
"text-align: center;\n"
"}\n"
"\n"
"QPushButton{\n"
"background-color:white;\n"
"width:150px;\n"
"height:125px;\n"
"font-size:150px;\n"
"border: none;\n"
"text-align: center;\n"
"}\n"
"\n"
"\n"
"\n"
"\n"
"QPushButton:pressed{\n"
"background-color: light silver\n"
"}\n"
"\n"
"\n"
"")
self.horizontalLayoutWidget = QtWidgets.QWidget(Form)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(9, 339, 571, 137))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout.setObjectName("horizontalLayout")
self.pushButton = QtWidgets.QPushButton(self.horizontalLayoutWidget)
self.pushButton.setObjectName("pushButton")
self.horizontalLayout.addWidget(self.pushButton)
self.pushButton_3 = QtWidgets.QPushButton(self.horizontalLayoutWidget)
self.pushButton_3.setObjectName("pushButton_3")
self.horizontalLayout.addWidget(self.pushButton_3)
self.pushButton_2 = QtWidgets.QPushButton(self.horizontalLayoutWidget)
self.pushButton_2.setObjectName("pushButton_2")
self.horizontalLayout.addWidget(self.pushButton_2)
self.label = QtWidgets.QLabel(Form)
self.label.setGeometry(QtCore.QRect(6, 20, 551, 51))
self.label.setObjectName("label")
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
global _translate
_translate = QtCore.QCoreApplication.translate
Form.setWindowTitle(_translate("Form", "Form"))
self.pushButton.setText(_translate("Form", "1"))
self.pushButton_3.setText(_translate("Form", "2"))
self.pushButton_2.setText(_translate("Form", "3"))
self.label.setText(_translate("Form", u"ПОЛЕ ДЛЯ ОТВЕТОВ"))
class Dialog(QtWidgets.QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("class Dialog")
self.resize(1200, 200)
self.setStyleSheet('background-color: red;')
#pass
class Form(QtWidgets.QWidget):
def __init__(self):
super(Form, self).__init__()
# self.dialog = Dialog() #
ui = Ui_Form()
ui.setupUi(self)
self.dialog = Dialog() # +
# ui.pushButton.clicked.connect(self.okno)
ui.pushButton.clicked.connect(self.bp1)
ui.pushButton_2.clicked.connect(self.bp2)
ui.pushButton_3.clicked.connect(self.bp3)
#ui.pushButton_3.clicked.connect(self.show_dialog) # +
#ui.pushButton_2.clicked.connect(self.hide_dialog) #
def proverka():
otvet_zagadka = zagadkaNumber + 1
if otvet_zagadka == otvet:
self.label.setText(_translate("Form", u"ВЕРНО"))
Form.setStyleSheet("QLabel{\n"
"background-color: white;\n"
"text-align: center;\n"
"}\n"
"\n"
"QPushButton{\n"
"background-color:white;\n"
"width:150px;\n"
"height:125px;\n"
"font-size:150px;\n"
"border: none;\n"
"text-align: center;\n"
"}\n"
"\n"
"\n"
"\n"
"\n"
"QPushButton:pressed{\n"
"background-color: light silver\n"
"}\n"
"\n"
"\n"
"QLabel{\n"
"background-color: green;\n"
"background-color: green;\n"
"background-color: green;\n"
"background-color: green;\n"
"background-color: green;\n"
"background-color: green;\n"
"background-color: green;\n"
"background-color: green;\n"
"background-color: green;\n"
"background-color: white;\n"
"")
if otvet_zagadka != otvet:
self.label.setText(_translate("Form", u"НЕВЕРНО, ПОПРОБУЙ ЕЩЕ"))
Form.setStyleSheet("QLabel{\n"
"background-color: white;\n"
"text-align: center;\n"
"}\n"
"\n"
"QPushButton{\n"
"background-color:white;\n"
"width:150px;\n"
"height:125px;\n"
"font-size:150px;\n"
"border: none;\n"
"text-align: center;\n"
"}\n"
"\n"
"\n"
"\n"
"\n"
"QPushButton:pressed{\n"
"background-color: light silver\n"
"}\n"
"\n"
"\n"
"QLabel{\n"
"background-color: red;\n"
"background-color: red;\n"
"background-color: red;\n"
"background-color: red;\n"
"background-color: red;\n"
"background-color: red;\n"
"background-color: red;\n"
"background-color: red;\n"
"background-color: red;\n"
"background-color: white;\n"
"")
def okno(self):
#Вывод окна
pyGame()
# def show_dialog(self):
# self.dialog.show()
# def hide_dialog(self):
# self.dialog.hide()
def bp1(self):
global otvet
otvet = 1
return otvet
def bp2(self):
global otvet
otvet = 2
return otvet
def bp3(self):
global otvet
otvet = 3
return otvet
def random1():
with open('zagadki.txt', 'r', encoding='UTF-8', ) as file:
global zagadka
global zagadkaNumber
lines = file.readlines()
linesNumbers = [0, 2, 4, 6, 8, 10, 12]
zagadkaNumber = random.choice(linesNumbers)
zagadka = lines[zagadkaNumber]
global text
global textRect
text = basicFont.render(zagadka, True, WHITE, BLUE)
textRect = text.get_rect()
textRect.centerx = windowSurface.get_rect().centerx
textRect.centery = windowSurface.get_rect().centery
def vivod_teksta():
# Нанесение текста на поверхность
windowSurface.blit(text, textRect)
def pyGame():
global zagadka
zagadka = random1()
# Настройка pygame
pygame.init()
# Нанесение на поверхность белого фона
windowSurface.fill(WHITE)
# Нанесение на поверхность зеленого многоугольника
pygame.draw.polygon(windowSurface, GREEN, ((146, 0), (291, 106), (236, 277), (56, 277), (0, 106)))
# Нанесение на поверхность синих линий
pygame.draw.line(windowSurface, BLUE, (60, 60), (120, 60), 4)
pygame.draw.line(windowSurface, BLUE, (120, 60), (60, 120))
pygame.draw.line(windowSurface, BLUE, (60, 120), (120, 120), 4)
# Нанесение на поверхность синего круга
pygame.draw.circle(windowSurface, BLUE, (300, 50), 20, 0)
#Нанесение на поверхность красного эллипса.
pygame.draw.ellipse(windowSurface, RED, (300, 250, 40, 80), 1)
#Нанесение на поверхность фонового прямоугольника для текста.
pygame.draw.rect(windowSurface, RED, (textRect.left - 500, textRect.top - 500, textRect.width + 100, textRect.height + 100))
# Получение массива пикселов поверхности
pixArray = pygame.PixelArray(windowSurface)
pixArray[480][380] = BLACK
del pixArray
vivod_teksta()
pygame.display.flip()
pygame.display.update()
mainClock.tick(40 )
Form().proverka()
# Запуск игрового цикла
while True:
for event in pygame.event.get():
if event.type == KEYDOWN :
if event.key == K_ESCAPE:
pygame.quit()
return
if event.type == QUIT:
pygame.quit()
return
# sys.exit()
pyGame()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = Form()
w.show()
sys.exit(app.exec_())