import os
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtCore import Qt
class EnterName(QWidget):
text_value = pyqtSignal(str)
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 300, 50)
self.setWindowTitle('Введите имя')
self.button = QPushButton('Сохранить', self)
self.button.clicked.connect(self.bEvent)
self.button.move(120, 30)
self.lEdid = QLineEdit(self)
self.lEdid.setGeometry(0, 0, 300, 30)
@pyqtSlot()
def bEvent(self):
self.text_value.emit(self.lEdid.text())
self.hide()
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 420, 280)
self.setWindowTitle('Exsample')
self.setWindowModality(Qt.WindowModal)
self.button = QPushButton('Имя', self)
self.button.move(180, 260)
self.button.clicked.connect(self.bEvent)
self.tb = QTextBrowser(self)
self.tb.setGeometry(0, 0, 420, 260)
self.eName = EnterName()
self.eName.text_value.connect(self.signalHandler)
def bEvent(self):
self.eName.show()
def signalHandler(self, text):
self.tb.append(text)
if __name__ == '__main__':
app = QApplication(sys.argv)
example = Example()
example.show()
sys.exit(app.exec_())
import os
import sys
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
def log_uncaught_exceptions(ex_cls, ex, tb):
import traceback
text = '{}: {}:\n\n'.format(ex_cls.__name__, ex)
text += ''.join(traceback.format_tb(tb))
QMessageBox.critical(None, 'Ошибка!', text)
sys.excepthook = log_uncaught_exceptions
class EnterName(QWidget):
text_value = pyqtSignal(str)
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 300, 50)
self.setWindowTitle('Введите имя')
self.button = QPushButton('Сохранить', self)
self.button.clicked.connect(self.bEvent)
self.button.move(120, 30)
self.lEdid = QLineEdit(self)
self.lEdid.setGeometry(0, 0, 300, 30)
@pyqtSlot()
def bEvent(self):
self.text_value.emit(self.lEdid.text())
self.hide()
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setGeometry(300, 300, 420, 280)
self.setWindowTitle('Exsample')
self.button = QPushButton('Имя', self)
self.button.move(180, 260)
self.button.clicked.connect(self.bEvent)
self.tb = QTextBrowser(self)
self.tb.setGeometry(0, 0, 420, 260)
self.eName = EnterName()
self.eName.text_value.connect(self.signalHandler)
def bEvent(self):
self.eName.show()
def signalHandler(self, text):
self.tb.append(text)
if __name__ == '__main__':
app = QApplication(sys.argv)
example = Example()
example.show()
sys.exit(app.exec_())
import sys
from PyQt5.QtWidgets import *
import rsa
class Example(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Пример")
self.textBrowser = QTextBrowser(self)
self.textBrowser.move(0, 50)
self.textEdit = QTextEdit(self)
self.textEdit.append("Hello world!")
text = self.textEdit.toPlainText()
(pubkey, privkey) = rsa.newkeys(700)
# шифруем
crypto = rsa.encrypt(text.encode(), pubkey)
print(crypto)
# записываем в файл
file = open("my_file.bin", "wb").write(crypto)
# открываем файл в режиме чтения байтов
file = open("my_file.bin", "rb").read()
#расшифровываем
self.text = rsa.decrypt(file, privkey)
self.textBrowser.append(self.text.decode())
print(text)
if __name__ == '__main__':
app = QApplication(sys.argv)
form = Example()
form.show()
app.exec()
'''
Программа для демонстрации перехвата событий мыши и клавиатуры виджеттом.
'''
import sys
from PyQt5.QtWidgets import QWidget, QApplication
from PyQt5.QtGui import QPainter, QPen
from PyQt5.QtCore import Qt
class MyWidget(QWidget):
def __init__(self):
super().__init__()
self.points = []
def mousePressEvent(self, e):
print("Mouse pressed at", e.x(), e.y())
self.points.append([e.x(), e.y()])
self.update() # вся перерисовка только через update,
# который сам вызовет paintEvent.
def mouseReleaseEvent(self, e):
print("Mouse released at", e.x(), e.y())
def mouseMoveEvent(self, e):
print("Mouse moved to", e.x(), e.y())
def keyPressEvent(self, e):
if e.key() == Qt.Key_Left:
print('Left')
elif e.key() == Qt.Key_Right:
print('Right')
elif e.key() == Qt.Key_Up:
print('Up')
elif e.key() == Qt.Key_Down:
print('Down')
print("Key pressed, text is", repr(e.text()))
def keyReleaseEvent(self, e):
print("Key released, text is", repr(e.text()))
def paintEvent(self, e):
p = QPainter()
p.begin(self)
pen = QPen(Qt.red, 10)
p.setPen(pen)
for x, y in self.points:
p.drawPoint(x, y)
p.end()
def main():
app = QApplication(sys.argv)
w = MyWidget()
w.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
import sys
from PyQt5.QtWidgets import (QWidget, QHBoxLayout, QLabel, QApplication)
from PyQt5.QtGui import QPixmap
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
hbox = QHBoxLayout(self)
pixmap = QPixmap("ёлка.png")
lbl = QLabel(self)
lbl.setPixmap(pixmap)
hbox.addWidget(lbl)
self.setLayout(hbox)
self.move(100, 200)
self.setWindowTitle('Red Rock')
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
i = int(input())
granitsa = int(input())
while i/2 and i%2 == 0 or i/3 and i%3 == 0 or i/4 and i%4 == 0 or i/5 and i%5 == 0 or i/6 and i%6 == 0 or i/7 and i%7 == 0 or i/8 and i%8 == 0 or i/9 and i%9 == 0:
i+=1
print(i)
print(str(i) + ' is sostavnoe')
if i >= granitsa:
print('BREAK')
break
print('Конец программы.')
<b>Нашёл на просторах интернета </b>
# Задача №1
# Простые числа
from time import sleep
def Prm(x):
if x == 2:
return True
if x < 2 or x % 2 == 0:
return False
for i in range(3, int(x**0.5) + 1, 2):
if x % i == 0:
return False
return True
for iterator in range(1,10000000000,1):
sleep(0.5)
print(str(iterator), Prm(iterator))
print('Hello!',input())
from subprocess import Popen,PIPE
process = Popen('py test.py', stdout=PIPE,stdin=PIPE,stderr=PIPE,shell=True)
data = process.communicate(b'developer.')[0].decode()
print(data)
import sys
from PyQt5.QtWidgets import (QWidget, QLabel,
QLineEdit, QApplication)
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.lbl = QLabel(self)
qle = QLineEdit(self)
qle.move(60, 100)
self.lbl.move(60, 40)
qle.textChanged[str].connect(self.onChanged)
self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('QLineEdit')
self.show()
def onChanged(self, text):
self.lbl.setText(text)
self.lbl.adjustSize()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())