Python Forum
Modify code from running program ?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Modify code from running program ?
#1
Hello i want to ask for help. I have simple quiz program with pyqt5. PRogram asks question and you fill a,b,c answers and it gives you your result in the end. I want to make extension window where i can add more questions to quiz. In my code i have list of questions and answers. I want to add more of them in running program.

Please can you guys help me with this?
Reply
#2
you can start by showing existing code.
Reply
#3
import sys from PyQt5 import QtWidgets from PyQt5.QtWidgets import QMainWindow,QDialog,QBoxLayout, QApplication, QWidget, QPushButton, QAction, QLineEdit, QMessageBox, QComboBox,QProgressBar,QLabel,QPlainTextEdit from PyQt5.QtGui import QPixmap from PyQt5.QtWidgets import * from PyQt5.QtGui import QIcon, QPixmap from PyQt5.Qt import QApplication from PyQt5.QtGui import QDesktopServices from PyQt5.QtCore import QUrl import subprocess import time import random import threading class Window(QMainWindow): def __init__(self): super().__init__() self.question_prompts = [ "What color are apples ?\n(a) Red/Green\n(b) Yellow\n(c) Pink\n", "What color are bananas ?\n(a) Teal\n(b) Yellow\n(c) Black\n", "What color are strawberry ?\n(a) yelow\n(b) black\n(c) red\n", "What color are toilets ?\n(a) yelow\n(b) black\n(c) red\n", "What color is ferrari ?\n(a) yelow\n(b) black\n(c) red\n" ] self.numberof = len(self.question_prompts) self.answers = ["a","b","c","d","e"] self.answers1= -1 self.score = 0 self.counter = 0 self.setFixedSize(400, 200) self.move(100,100) self.setWindowTitle("quiz") self.b1 = QtWidgets.QPushButton(self) self.b1.setText("Next") self.b1.move(240, 120) self.b1.resize(90, 32) self.b1.clicked.connect(self.next) self.b2 = QtWidgets.QPushButton(self) self.b2.setText("Back") self.b2.move(150, 120) self.b2.resize(90, 32) self.b2.clicked.connect(self.back) self.b2.setDisabled(False) self.textbox1 = QLineEdit(self) self.textbox1.move(50, 110) self.textbox1.resize(100, 32) self.textbox1.setPlaceholderText("Answer") self.textbox1Value = self.textbox1.text() self.label2 = QtWidgets.QLabel(self) self.label2.move(48, 40) self.label2.resize(130, 70) self.label2.setText(str(self.question_prompts[self.counter])) self.update() self.show() def next(self): if self.counter < self.numberof-1: self.counter += 1 self.answers1 +=1 self.label2.setText(str(self.question_prompts[self.counter])) if self.textbox1.text() == self.answers[self.answers1]: self.score += 1 self.textbox1.clear() else: if self.textbox1.text() == self.answers[self.counter]: self.score += 1 self.label2.setText("You got " + str(self.score) + " from " + str(len(self.question_prompts)) + " right ") self.counter +=1 self.b1.disconnect() def back(self): if self.counter != self.numberof and self.counter !=0: self.counter = self.counter - 1 self.answers1 = self.answers1 -1 self.label2.setText(str(self.question_prompts[self.counter])) if __name__ == "__main__": app = QApplication(sys.argv) window = Window() sys.exit(app.exec())
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  code not running even without errors Azdaghost 2 1,007 Apr-25-2025, 07:35 PM
Last Post: Azdaghost
  python code not running Azdaghost 1 800 Apr-22-2025, 08:44 PM
Last Post: deanhystad
  writing and running code in vscode without saving it akbarza 5 4,661 Mar-03-2025, 08:14 PM
Last Post: Gribouillis
  problem in running a code akbarza 7 3,292 Feb-14-2024, 02:57 PM
Last Post: snippsat
  the order of running code in a decorator function akbarza 2 1,912 Nov-10-2023, 08:09 AM
Last Post: akbarza
  Program running on RPi 3b+ Very Strange Behavior - Out of Bound Index MadMacks 26 10,035 Mar-07-2023, 09:50 PM
Last Post: MadMacks
  Code running many times nad not just one? korenron 4 2,772 Jul-24-2022, 08:12 AM
Last Post: korenron
  Error while running code on VSC maiya 4 8,145 Jul-01-2022, 02:51 PM
Last Post: maiya
  running a TensorFlow program Led_Zeppelin 0 1,680 Apr-07-2022, 06:33 PM
Last Post: Led_Zeppelin
  code running for more than an hour now, yet didn't get any result, what should I do? aiden 2 3,000 Apr-06-2022, 03:41 PM
Last Post: Gribouillis

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.