'''
Программа для демонстрации перехвата событий мыши и клавиатуры виджеттом.
'''
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_())
import os
dll_name = os.path.join(os.path.dirname(__file__), 'avbin')
pyglet.lib.load_library(dll_name)