I am trying to create a UI for a text game.
This works fine, however I wanted to create my own simple print function to print to the parts of the UI (in the example the QLabel) this works, if the function is in the UI file but when I move the functions to another file, I get
"AttributeError: type object 'Window' has no attribute 'label'"
even though my IDE says Window.label exists before running it.
Is this some quirk or QT? or am I making a mistake?
UI.py
import sys
from PyQt5 import QtWidgets, QtGui, QtCore
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
class Window(QWidget):
def __init__(self):
super().__init__()
self.show()
import game
self.label = QLabel("Text")
self.label.setAlignment(Qt.AlignCenter | Qt.AlignTop)
self.output = QTextEdit()
self.output.setReadOnly(True)
grid = QGridLayout()
grid.setSpacing(10)
grid.addWidget(self.label,0,0,1,10)
grid.addWidget(self.output,1,0,10,10)
self.setLayout(grid)
game.Game.test()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Window()
sys.exit(app.exec_())
Game.py
from UI import Window
class Game():
def print_UI(self,*Args, **Kwargs):
Window.setup.output.insertPlainText(*Args, **Kwargs)
def print_label(self,*Args, **Kwargs):
Window.label.setText(*Args, **Kwargs)
def test():
Game.print_label("HI")