Please Help
-
I am attempting to create a basic shopping cart package for my university course and have used the following code:
import sys
import ospip install PySide2
from PySide2 import QtGui, QtWidgets, QtCore
from PySide2.QtCore import *
from PySide2.QtWidgets import *
from PySide2.QtUiTools import *cartItems = []
cartAnnualTotal = 8250.00
IntAnnualPrices = {'Art Intervention': 200.00,'Behaviour Intervention': 187.50,'Collaborative Problem Solving': 104.00,'Learning Mentor': 13.00,'Self Regulation': 1040.00,'1 to 1 Tuition': 360.00,'Outdoor Learning': 216.00,'Parental Engagement': 350.00,'Phonics': 120.00,'Reading Comprehension': 120.00,'Reduced Class Sizes': 0.00,'Social and Emotional Learning': 1040.00,'Summer School': 120.00,'Teaching Assistant Intervention': 2200.00,'Youth Drugs and Alcohol YDAP': 2160.00,'Youth Offending Services': 2160.00,'Educational Psychologist': 5400.00,'Education 5 Attendance Support': 225.00,'Early Help Worker': 1968.33,'Family Liason Officer': 350.00,'Century Online Learning Platform': 400.00,'Lexonic Literacy Support': 62.50,'Chances Football Coaching': 360.00,'Cahms Support': 420.00,'CYPS': 420.00,'EHCP Application': 5500.00,'Exam Access Arrangement Testing': 60.00,'Anger Management': 13.00}
IntTermPrices = {'Art Intervention': 66.67,'Behaviour Intervention': 62.50,'Collaborative Problem Solving': 34.67,'Learning Mentor': 4.33,'Self Regulation': 346.67,'1 to 1 Tuition': 120.00,'Outdoor Learning': 72.00,'Parental Engagement': 116.67,'Phonics': 40.00,'Reading Comprehension': 40.00,'Reduced Class Sizes': 0.00,'Social and Emotional Learning': 346.67,'Summer School': 40.00,'Teaching Assistant Intervention': 733.33,'Youth Drugs and Alcohol YDAP': 720.00,'Youth Offending Services': 720.00,'Educational Psychologist': 1800.00,'Education 5 Attendance Support': 75.00,'Early Help Worker': 656.11,'Family Liason Officer': 116.67,'Century Online Learning Platform': 133.33,'Lexonic Literacy Support': 20.83,'Chances Football Coaching': 120.00,'Cahms Support': 140.00,'CYPS': 140.00,'EHCP Application': 1800.00,'Exam Access Arrangement Testing': 20.00,'Anger Management': 4.33}
class Form(QObject):
def init(self, ui_file, parent = None):
super(Form, self).init(parent)#Load UI File ui_file = QFile(ui_file) ui_file.open(QFile.ReadOnly) loader = QUiLoader() self.window = loader.load(ui_file) ui_file.close() #Initialise User Interface Items cmbInterventionsList = self.window.findChild(QComboBox, 'cmbInterventionsList') btnAdd = self.window.findChild(QPushButton, 'btnAdd') cmbInterventionsList.addItem("Art Intervention") cmbInterventionsList.addItem("Behaviour Intervention") cmbInterventionsList.addItem("Collaborative Problem Solving") cmbInterventionsList.addItem("Learning Mentor") cmbInterventionsList.addItem("Self Regulation") cmbInterventionsList.addItem("1 to 1 Tuition") cmbInterventionsList.addItem("Outdoor Learning") cmbInterventionsList.addItem("Parental Engagement") cmbInterventionsList.addItem("Phonics") cmbInterventionsList.addItem("Reading Comprehension") cmbInterventionsList.addItem("Reduced Class Sizes") cmbInterventionsList.addItem("Social and Emotional Learning") cmbInterventionsList.addItem("Summer School") cmbInterventionsList.addItem("Teaching Assistant Intervention") cmbInterventionsList.addItem("Youth Drugs and Alcohol YDAP") cmbInterventionsList.addItem("Youth Offending Services") cmbInterventionsList.addItem("Educational Psychologist") cmbInterventionsList.addItem("Education 5 Attendance Support") cmbInterventionsList.addItem("Early Help Worker") cmbInterventionsList.addItem("Family Liason Officer") cmbInterventionsList.addItem("Century Online Learning Platform") cmbInterventionsList.addItem("Lexonic Literacy Support") cmbInterventionsList.addItem("Chances Football Coaching") cmbInterventionsList.addItem("Cahms Support") cmbInterventionsList.addItem("CYPS") cmbInterventionsList.addItem("EHCP Application") cmbInterventionsList.addItem("Exam Access Arrangement Testing") cmbInterventionsList.addItem("Anger Management") #Make Click on Button btnAdd.clicked.connect(self.updateInt) self.window.show()
def addIntervention(self, itemName):
# Add the current item in combo box to a list and list view
cmbInterventionsList = self.window.findChild(QComboBox, 'cmbInterventionsList')
lstViewInterventions = self.window.findChild(QListWidget, 'lstViewInterventions')lstViewInterntions.addItem(cmbInterventionsList.currentText) cartItems.append(itemName)
def updateInt(self):
global cartItems, cartAnnualTotal, IntAnnualPricescmbInterventionsList = self.window.findChild(QComboBox, 'cmbInterventionsList') lblSummary = self.window.findChild(QLabel, 'lblSummary') lblTotal = self.window.findChild(QLabel, 'lblTotal') #Add Button Click self.addIntervention(cmbInterventionsList.currentText()) #Update Cart Summary cartSummary = dict((item, cartItems.count(item)) for item in cartItems) lblSummary.setText(str(cartSummary)) #Loop Through All Items in Cart, Select Prices and Add to Total for item in cartItems: itemPrice = IntAnnualPrices.get(item, 0) cartAnnualTotal += itemPrice lblTotal.setText(str(cartAnnualTotal)) cartAnnualTotal = 0
if name == 'main':
app = QApplication(sys.argv)# Load UI form = Form('CM.ui') sys.exit(app.exec_())
however the section of code that stats if name
crashes in google collab and restarts the Kernel
Can anyone help me fix this issue and or explain this?
much appreciated
-
Hi and welcome to devnet,
Google colab ? I am currently not sure you can run a Qt application as the one you build in that environment.
The crash logs shows the usual error with regard to the xcb plugin that is not loading which I can understand since there's no X server involved in Google Colab.
Since you are using Google Collab, shouldn't you rather use ipywidgets ?
On a side note, please use coding tags when posting code to make it readable.
-
The most simple would be to do that on your own machine using a virtual environment. You can use either conda or pip's virtualenv. You also might want to move to PySide6.