Python Forum
[PyQt] call a function with parametrs from another class
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[PyQt] call a function with parametrs from another class
#1
hi;
instead of creating a function for each tablewidget to initialize it, I would like to create a function in a class then I call this function in another class, making it assign as parameter the name of the tablewidgte to initialize :
Here is a sample of the code :

#!/usr/bin/python3
# -*- coding: utf-8 -*-
from PyQt5.QtWidgets  import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *

class prototype():
     def __init__() :
         tablewidget=QTableWidget
    #function to initialize tablewidgte :
    def initialiser_tablewidget(self,tableWidget):
        self.tableWidget.clear() # effacer contenu
        self.tableWidget.setHorizontalHeaderItem(0, QTableWidgetItem("date"))
        self.tableWidget.setHorizontalHeaderItem(1, QTableWidgetItem("hour"))
        self.tableWidget.setHorizontalHeaderItem(2, QTableWidgetItem("Monitor1"))
        self.tableWidget.setHorizontalHeaderItem(3, QTableWidgetItem("Monitor2"))


class MainApp(QMainWindow) :
    
    def __init__(self,parent=None) :
        super(MainApp,self).__init__(parent)
        QMainWindow.__init__(self)
        self.win_UI() 
        self.prototype= prototype()
    def win_UI(self):
        self.setWindowTitle("ddm corrector")
        self.setGeometry(10,40,1140,653)
        #initialize tablewidgte_1
        prototype.intialiser_tableWidget(tablewidgte_1)
        #initialize tablewidgte_2
        prototype.intialiser_tableWidget(tablewidgte_2)

def main():
    app=QApplication(sys.argv)
    win=MainApp()
    win.show()
    app.exec_()# infinite loop
if __name__=='__main__' :
    main()
Reply


Messages In This Thread
call a function with parametrs from another class - by atlass218 - Feb-20-2020, 02:16 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  GUI Problem / call another function / fill QListwidget flash77 5 892 Jul-30-2023, 04:29 PM
Last Post: flash77
  simple tkinter question function call not opening image gr3yali3n 5 3,459 Aug-02-2022, 09:13 PM
Last Post: woooee
  [PyQt] Call a function in FormA from FormB panoss 3 1,906 Jan-30-2022, 07:45 PM
Last Post: panoss
  Call local variable of previous function from another function with Python3 & tkinter Hannibal 5 4,460 Oct-12-2020, 09:16 PM
Last Post: deanhystad
  Class function does not create command button Heyjoe 2 2,287 Aug-22-2020, 08:06 PM
Last Post: Heyjoe
  [Tkinter] Use function from other class (Tkinter) zarize 8 4,852 Aug-17-2020, 09:47 AM
Last Post: zarize
  [Tkinter] Call a class method from another (Tk GUI) class? Marbelous 3 6,241 Jan-15-2020, 06:55 PM
Last Post: Marbelous
  [Tkinter] Call a function when switching layouts 4096 0 3,545 Sep-22-2019, 07:39 PM
Last Post: 4096
  [PyQt] call a function in another class darktitan 6 14,158 Jun-22-2019, 03:33 AM
Last Post: darktitan
  [Tkinter] Bringing function out of class into main loop zukochew 1 2,687 Jul-30-2018, 06:43 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020