Good evening, dear friends!
Please, help ....
There is a program that, when a button is pressed, gives a line in the QMessageBox with the name of the movie. Previously, I have not come across COMBOBOX.
Please help: ______________________________Console_______________________________
import random a = [ #ΠΠΎΠ΅Π²ΠΈΠΊ "ΠΠ΅Π·ΡΠΌΠ½ΡΠΉ ΠΠ°ΠΊΡ: ΠΠΎΡΠΎΠ³Π° ΡΡΠΎΡΡΠΈ\n2015 Π³.\nIMDb: 8,1", "ΠΠ°Π»ΡΡ Π½Π° Π΄ΡΠ°ΠΉΠ²Π΅\n2017 Π³.\nIMDb: 7,7", "ΠΡΡΠΈΡΠ΅Π»ΠΈ\n2012 Π³.\nIMDb: 8,1" ] b = [ #ΠΠΎΠ΅Π½Π½ΡΠΉ "ΠΡΠ°ΠΊΠ° Π½Π° ΠΠ΅ΡΠ» Π₯Π°ΡΠ±ΠΎΡ\n2011 Π³.\nIMDb: 6.8", "Π―ΡΠΎΡΡΡ\n2014 Π³.\nIMDb: 7.6", "Π‘ΠΏΠ°ΡΡΠΈ ΡΡΠ΄ΠΎΠ²ΠΎΠ³ΠΎ Π Π°ΠΉΠ°Π½Π°\n1998 Π³.\nIMDb: 8.6" ] c = [ #ΠΠ΅ΡΠ΅ΠΊΡΠΈΠ² "ΠΠ΅Π»Π΅Π½Π°Ρ ΠΌΠΈΠ»Ρ\n1999 Π³.\nIMDb: 8.5", "ΠΠ°ΡΠ°Π»ΠΎ\n2010 Π³.\nIMDb: 8.8", "ΠΡΠ΅ΡΡΠΈΠΆ\n2006 Π³.\nIMDb: 8.5" ] while True: rez = (input("ΠΠ²Π΅Π΄ΠΈΡΠ΅ ΠΆΠ°Π½Ρ (a,b,c): ")) if rez == 'a': print (random.choice(a)) elif rez == 'b': print (random.choice(b)) elif rez == 'c': print (random.choice(c)) else: break print() __________________________Template of Main________________________________
import sys # ΠΠΌΠΏΠΎΡΡΠΈΡΡΠ΅ΠΌ Π½Π°Ρ ΠΈΠ½ΡΠ΅ΡΡΠ΅ΠΉΡ ΠΈΠ· ΡΠ°ΠΉΠ»Π° from design import * #UI file from PyQt5 import QtCore, QtGui, QtWidgets class MyWin(QtWidgets.QMainWindow): def __init__(self, parent=None): QtWidgets.QWidget.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) # ΠΠ΄Π΅ΡΡ ΠΏΡΠΎΠΏΠΈΡΡΠ²Π°Π΅ΠΌ ΡΠΎΠ±ΡΡΠΈΠ΅ Π½Π°ΠΆΠ°ΡΠΈΡ Π½Π° ΠΊΠ½ΠΎΠΏΠΊΡ self.ui.pushButton.clicked.connect(self.MyFunction) # ΠΠΎΠΊΠ° ΠΏΡΡΡΠ°Ρ ΡΡΠ½ΠΊΡΠΈΡ ΠΊΠΎΡΠΎΡΠ°Ρ Π²ΡΠΏΠΎΠ»Π½ΡΠ΅ΡΡΡ ΠΏΡΠΈ Π½Π°ΠΆΠ°ΡΠΈΠΈ Π½Π° ΠΊΠ½ΠΎΠΏΠΊΡ def MyFunction(self): pass if __name__=="__main__": app = QtWidgets.QApplication(sys.argv) myapp = MyWin() myapp.show() sys.exit(app.exec_()) ______________________________UI________________________________
# -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'design.ui' # # Created by: PyQt5 UI code generator 5.11.3 # # WARNING! All changes made in this file will be lost! from PyQt5 import QtCore, QtGui, QtWidgets class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName("MainWindow") MainWindow.resize(200, 220) MainWindow.setMinimumSize(QtCore.QSize(200, 220)) MainWindow.setMaximumSize(QtCore.QSize(200, 220)) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap("Icons8-Ios7-Cinema-Documentary.ico"), QtGui.QIcon.Normal, QtGui.QIcon.Off) MainWindow.setWindowIcon(icon) MainWindow.setAccessibleName("") self.centralwidget = QtWidgets.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.label = QtWidgets.QLabel(self.centralwidget) self.label.setGeometry(QtCore.QRect(10, 10, 151, 21)) self.label.setObjectName("label") self.pushButton = QtWidgets.QPushButton(self.centralwidget) self.pushButton.setGeometry(QtCore.QRect(10, 140, 121, 31)) self.pushButton.setObjectName("pushButton") self.label_2 = QtWidgets.QLabel(self.centralwidget) self.label_2.setGeometry(QtCore.QRect(10, 50, 111, 21)) self.label_2.setObjectName("label_2") self.comboBox = QtWidgets.QComboBox(self.centralwidget) self.comboBox.setGeometry(QtCore.QRect(10, 80, 121, 22)) self.comboBox.setMaxVisibleItems(8) self.comboBox.setFrame(True) self.comboBox.setObjectName("comboBox") self.comboBox.addItem("") self.comboBox.addItem("") self.comboBox.addItem("") MainWindow.setCentralWidget(self.centralwidget) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): _translate = QtCore.QCoreApplication.translate MainWindow.setWindowTitle(_translate("MainWindow", "Know You Better")) self.label.setText(_translate("MainWindow", "ΠΠΎΠΌΠΎΡΡ ΠΠ°ΠΌ Π²ΡΠ±ΡΠ°ΡΡ ΡΠΈΠ»ΡΠΌ?!")) self.pushButton.setText(_translate("MainWindow", "ΠΠ°ΠΆΠΌΠΈΡΠ΅ Π½Π° ΠΌΠ΅Π½Ρ")) self.label_2.setText(_translate("MainWindow", "ΠΡΠ±Π΅ΡΠΈΡΠ΅ ΠΆΠ°Π½Ρ")) self.comboBox.setCurrentText(_translate("MainWindow", "ΠΠΎΠ΅Π²ΠΈΠΊ")) self.comboBox.setItemText(0, _translate("MainWindow", "ΠΠΎΠ΅Π²ΠΈΠΊ")) self.comboBox.setItemText(1, _translate("MainWindow", "ΠΠΎΠ΅Π½Π½ΡΠΉ")) self.comboBox.setItemText(2, _translate("MainWindow", "ΠΠ΅ΡΠ΅ΠΊΡΠΈΠ²")) 