[Python] Calling def from inside of another def

Discussão em 'Python' iniciado por Stack, Agosto 6, 2025.

  1. Stack

    Stack Membro Participativo

    I want to call a def that is inside of another def Example:

    def 1(a,b):
    Print(a,b)

    Def 2 (c,d):
    Print(c,d)


    The thing i want to do is like we call a function from a class like

    class().def(variables)


    Iwant to do something like the above code Something like

    def1().def2(variables)


    Thanks :D

    Ihave this code

    # -*- coding: utf-8 -*-

    # Form implementation generated from reading ui file '2.ui'
    #
    # Created by: PyQt5 UI code generator 5.15.4
    #
    # WARNING: Any manual changes made to this file will be lost when pyuic5 is
    # run again. Do not edit this file unless you know what you are doing.

    from io import StringIO
    from typing import Text
    from PyQt5 import QtCore, QtGui, QtWidgets

    from PyQt5.QtCore import QTime, QTimer
    import sys
    import time

    from PyQt5 import QtTest




    class Ui_MainWindow(object):











    def setupUi(self, MainWindow):



    self.Console = QtWidgets.QTextEdit()
    self.Console.setGeometry(QtCore.QRect(240, 350, 461, 121))
    self.Console.setObjectName("Console")

    MainWindow.setObjectName("MainWindow")
    MainWindow.resize(800, 600)
    self.centralwidget = QtWidgets.QWidget(MainWindow)
    self.centralwidget.setObjectName("centralwidget")
    self.pushButton1 = QtWidgets.QPushButton(self.centralwidget)
    self.pushButton1.setGeometry(QtCore.QRect(260, 160, 341, 111))
    self.pushButton1.setObjectName("pushButton1")
















    MainWindow.setCentralWidget(self.centralwidget)
    self.menubar = QtWidgets.QMenuBar(MainWindow)
    self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
    self.menubar.setObjectName("menubar")
    MainWindow.setMenuBar(self.menubar)
    self.statusbar = QtWidgets.QStatusBar(MainWindow)
    self.statusbar.setObjectName("statusbar")
    MainWindow.setStatusBar(self.statusbar)

    self.retranslateUi(MainWindow)
    QtCore.QMetaObject.connectSlotsByName(MainWindow)




    def printer (text):






    sys.stdout = StringIO()
    print(text)
    time.sleep(0.05)

    self.Console.setText(sys.stdout.getvalue())









    def retranslateUi(self, MainWindow):
    _translate = QtCore.QCoreApplication.translate
    MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
    self.pushButton1.setText(_translate("MainWindow", "PushButton"))









    Ui_MainWindow.printer("hi")


    QtTest.QTest.qWait(5000)










    if __name__ == "__main__":
    import sys
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = QtWidgets.QMainWindow()
    ui = Ui_MainWindow()
    ui.setupUi(MainWindow)
    MainWindow.show()
    sys.exit(app.exec_())


    I need to call the printer Function but i cant

    I tried to make q text object global but i get error The print hi command doesnt work because printer fumc is on another func

    Continue reading...

Compartilhe esta Página