I have a main file, which handles my PyQt5 UI. I have the program create a new table for each set of data I have, and name it accordingly. The update_status
function edits a certain item on a certain table by the ID I gave it.
mainfile.py
class MyUi(object)
def setupUi(self, MyWindow):...
def retranslateUi(self, MyWindow):...
# this is what I want to call from another file
def update_status(self, tid, text):
# getting task's group for writing to table
t_file = json.load(open('Data/Tasks/tasks.json', 'r'))
for group in t_file:
for task in group['tasks']:
if task['id'] == tid:
task_parent = group['group name']
for i in self.TaskScreen.children():
if str(i.__class__.__name__) == 'QTableWidget':
try:
if i.objectName() == task_parent:
row = i.rowCount()
for r in range(row):
task_id = i.item(r, 0).text()
if task_id == tid:
i.setItem(r, 6, QtWidgets.QTableWidgetItem(str(text)))
i.update()
except UnboundLocalError:
print('Item doesnt exist')
When I call update_status
from mainfile.py, it works fine.
test.py (the file I need to call update_status
from)
from mainfile import MyUi
update_status = MyUi().update_status
update_status(tid='ABC123', text='Test')
This is the traceback I get:
AttributeError: 'MyUi' object has no attribute 'TaskScreen'
I hope I explained this well, Any help would be appreciated.