I don't know what happen my code.
I can't rebuild some error.
import os
from PyQt5.QtWidgets import QWidget, QApplication, QToolTip, QPushButton, QMainWindow
from time import strftime
Unused import ospylint(unused-import)
Undefined variable: 'QtWidgets'Python(undefined-variable)
Related
I had a PyQT Project which was working very well 1-2 months ago. I made some changes (not in the PyQT Project, but in other python files in same directory) and then ran the same PyQT Project again, but now it is giving me error.
The error is as follows,
PySide2/__init__.py: Unable to import shiboken2 from e:\Programming\PyQT\Second_Project,
At the end of the error, I found this ImportError,
ImportError: DLL load failed: The specified procedure could not be found.
I have tried lots of things but still I could not find any solution to this. I tried to re-install the PySide2 but to no use. I tried to change my Python Interpreter from 3.6.0 to 3.8.6 and also 3.9.2 but again, I got the same error. I also tried other different things answered in various Stackoverflow posts but nothing has seemed to work for me.
Can anyone help me how do I resolve this? I am 100% sure that the changes I made in other python files have absolutely nothing to do with this PyQT Project and this problem did not occur because of those changes.
The lines on which I got errors are,
from PySide2 import shiboken2 # Added this line later because shiboken2 wasn't being imported, but still it did not work
import iconify as ico
from iconify.qt import QtGui as IconQtGui, QtWidgets as IconQtWidgets
import PySide2
All the imports that I am making in my main.py file,
import sys
import os
from PyQt5.sip import delete
from PySide2 import shiboken2
# import iconify as ico
from iconify.qt import QtGui as IconQtGui, QtWidgets as IconQtWidgets
import PySide2
import mysql.connector as mc
from qt_material import *
# from PyQt5 import QtWidgets, uic, QtGui
from functools import partial
# from PyQt5.QtCore import Qt
from registered_courses import reg_data
from add_section_page import Ui_Add_Section_Window
from edit_section_page import Ui_Edit_Section_Window
from add_course_page import Ui_Add_Course_Window
from edit_course_page import Ui_Edit_Course_Window
from add_room_page import Ui_Add_Room_Window
from edit_room_page import Ui_Edit_Room_Window
from add_teacher_page import Ui_Add_Teacher_Window
from edit_teacher_page import Ui_Edit_Teacher_Window
from add_registered_course import Ui_Add_Registered_Course_Window
from edit_registered_course import Ui_Edit_Registered_Course_Window
from registered_section_student_details import Ui_Registered_Section_Students_Window
from add_section_student_page import Ui_Add_Section_Student_Window
from add_room_preferences import Ui_Add_Room_Preferences_Teacher_Window
from add_slot_preferences import Ui_Add_Slot_PReferences_Teacher_Window
import sections_timetable
import rooms_timetable
import teachers_timetable
from time_table import *
from student_clashes import *
from teacher_clashes import *
from room_clashes import *
from stylesheet import *
from util import *
#####################################
# Import GUI File
from ui_interface import *
Also, these are all the imports that are being made in my ui_interface file (the python file that is being generated by the Qt Designer)
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'interfaceGufDiZ.ui'
##
## Created by: Qt User Interface Compiler version 5.14.1
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide2.QtCore import (QCoreApplication, QMetaObject, QObject, QPoint,
QRect, QSize, QUrl, Qt)
from PySide2.QtGui import (QBrush, QColor, QConicalGradient, QCursor, QFont,
QFontDatabase, QIcon, QLinearGradient, QPalette, QPainter, QPixmap,
QRadialGradient)
from PySide2.QtWidgets import *
import icons_rc
I've been programming in python three for about a week now, and I'm trying to insert some of these imports below. Where it's marked is where I'm having errors that will state
from PyQt5 import QtSql, uic <=== Right here
from PyQt5.uic import loadUi <=== Right here
from PyQt5.QtWidgets import *
from PyQt5.QtSql import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import pyrebase
import sqlite3
Where it's marked is where I'm having errors that will state
Cannot find reference 'uic' in '__init__pyi'
Icons are not showing in my QListWidgetItems.
Edit 2:
Turns out you can't use absoulte path. You must use relative path. But why is this the case?
Minimum reproducible example:
import json
import os
import sys
from math import floor
from PyQt5 import QtTest, QtGui
from PyQt5.QtDesigner import QFormBuilder
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QApplication, QFrame, QGridLayout, QLabel, QMainWindow, QScrollArea, QWidget, QVBoxLayout, \
QListView, QListWidget, QListWidgetItem, QToolButton
from PyQt5.QtCore import QPoint, Qt, QIODevice, QFile
from PyQt5.Qt import QPixmap
class MainWindow(QMainWindow):
def __init__(self, *args, obj=None, **kwargs):
super(MainWindow, self).__init__(*args, **kwargs)
#ListWidget
listWidget = QListWidget(self)
listWidget.setViewMode(QListWidget.IconMode)
listWidget.setFixedSize(500, 700)
dir = r'Players'
for filename in os.listdir(dir):
#Item
item = QListWidgetItem(QIcon('Players/Pogba.jpg'), '<Name>', listWidget)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = MainWindow()
window.showMaximized()
app.exec_()
I followed the docs(https://doc.qt.io/qt-5/qlistwidgetitem.html), so why are they not appearing?
Edit:
It looks like it only happens when the image is outside the source code's folder. Why is this the case?
I have added PyQt5 Browser to my project but when show() method is executed, it blocks the codes following it. Is there a way, not show it as modal, or have it run on another thread?
This is the code I have taken from Python Tutorials site, which works perfect, but just blocks the code on show():
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtWebKit import *
from PyQt5.QtWebKitWidgets import *
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow
app = QApplication(sys.argv)
web = QWebView()
web.load(QUrl("https://pythonspot.com"))
web.show()
# the code in here won't run while the form web.show() opened, is not closed
sys.exit(app.exec_())
I have a problem with my PyQt button action. I would like to send a String with the Function but I got this Error:
TypeError: argument 1 has unexpected type 'NoneType'
import sys
from PyQt5.QtWidgets import QApplication, QPushButton, QAction
from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtGui import *
from PyQt5.uic import *
app = QApplication(sys.argv)
cocktail = loadUi('create.ui')
def mixCocktail(str):
cocktail.show()
cocktail.showFullScreen()
cocktail.lbl_header.setText(str)
widget = loadUi('drinkmixer.ui')
widget.btn_ckt1.clicked.connect(mixCocktail("string"))
widget.show()
sys.exit(app.exec_())
As suggested by user3030010 and ekhumoro it expects a callable function. In which case you should replace that argument with lambda: mixCocktail("string")
AND ALSO don't use str it's a python built-in datatype I have replaced it with _str
import sys
from PyQt5.QtWidgets import QApplication, QPushButton, QAction
from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtGui import *
from PyQt5.uic import *
app = QApplication(sys.argv)
cocktail = loadUi('create.ui')
def mixCocktail(_str):
cocktail.show()
cocktail.showFullScreen()
cocktail.lbl_header.setText(_str)
widget = loadUi('drinkmixer.ui')
widget.btn_ckt1.clicked.connect(lambda: mixCocktail("string"))
widget.show()
sys.exit(app.exec_())
More about lambda functions: What is a lambda (function)?
instead of this
widget.btn_ckt1.clicked.connect(mixCocktail("string"))
write
widget.btn_ckt1.clicked.connect(lambda:mixCocktail("string"))