TI/PyQt5
Z Brain-wiki
przyklad 1
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'Guzik'
self.left = 10
self.top = 10
self.width = 220
self.height = 220
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
self.guzik= QPushButton('X', self)
self.guzik.move(10,10)
self.guzik.resize(200,200)
self.guzik.clicked.connect(self.on_click)
self.show()
def on_click(self):
if self.guzik.text()=='X':
self.guzik.setText('O')
else:
self.guzik.setText('X')
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())
GUI do kółko i krzyzyk
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton
class MojGuzik(QPushButton):
def __init__(self,i,j,*args):
super().__init__('',*args)
self.i=i
self.j=j
self.move(10+100*self.i,10+100*self.j)
self.resize(100,100)
self.clicked.connect(self.po_kliknieciu)
def po_kliknieciu(self):
if self.text()=='X':
self.setText('O')
else:
self.setText('X')
class App(QWidget):
def __init__(self):
super().__init__()
self.title = 'Guzik'
self.left = 10
self.top = 10
self.width = 320
self.height = 320
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
for x in range(3):
for y in range(3):
MojGuzik(x,y, self)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
sys.exit(app.exec_())