Advertisement
Guest User

Untitled

a guest
Sep 29th, 2019
253
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.64 KB | None | 0 0
  1. import sys
  2. from PyQt5.QtWidgets import *
  3.  
  4.  
  5. class Example(QWidget):
  6. def __init__(self):
  7. super().__init__()
  8. self.initUI()
  9.  
  10. def initUI(self):
  11. self.symbol = ""
  12. self.setGeometry(300, 300, 500, 500)
  13. self.setWindowTitle('Крестики-нолики')
  14.  
  15. self.choose = QLabel(self)
  16. self.choose.setText("Выберите знак")
  17. self.choose.move(200, 320)
  18.  
  19. self.x_radiobutton = QRadioButton("X", self)
  20. self.x_radiobutton.move(200, 340)
  21. self.null_radiobutton = QRadioButton("0", self)
  22. self.null_radiobutton.move(250, 340)
  23. self.x_radiobutton.clicked.connect(self.x_symbol)
  24. self.null_radiobutton.clicked.connect(self.null_symbol)
  25.  
  26.  
  27. self.list_buttons = [[QPushButton("", self) for i in range(3)] for j in range(3)]
  28. for i in range(1, 4):
  29. for j in range(3):
  30. self.list_buttons[i - 1][j].resize(100, 100)
  31. self.list_buttons[i - 1][j].move(i * 100, j * 100)
  32. self.list_buttons[i - 1][j].clicked.connect(lambda: self.update_button(self.list_buttons[i - 1][j]))
  33.  
  34. def update_button(self, button):
  35. button.setText(self.symbol)
  36.  
  37. def x_symbol(self):
  38. self.symbol = "X"
  39. self.x_radiobutton.setDisabled(True)
  40. self.null_radiobutton.setDisabled(True)
  41.  
  42. def null_symbol(self):
  43. self.symbol = "0"
  44. self.x_radiobutton.setDisabled(True)
  45. self.null_radiobutton.setDisabled(True)
  46.  
  47.  
  48. if __name__ == '__main__':
  49. app = QApplication(sys.argv)
  50. ex = Example()
  51. ex.show()
  52. sys.exit(app.exec())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement