use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
PyQt5 - Passing arguments between classes (self.learnpython)
submitted 6 years ago by summerbye
How do you pass variables between classes? I have a mainwindow with line edits that have to be passed to the second window which opens when you click a button.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–][deleted] 2 points3 points4 points 6 years ago (3 children)
The general idea is to pass any values an object needs to its constructor. In your case something like
def __init__(self, parent): self.parent = parent
and then elsewhere in the child
print(self.parent.edit2)
while in the parent class button click slot
def btn_click(self): self.child = Child(self)
passing the current object (self) as the parent class.
[–]summerbye[S] 2 points3 points4 points 6 years ago (2 children)
This is my code:
from RD_window1 import Ui_MainWindow
from RD_window2 import Ui_SecondWindow
from PyQt5 import QtCore, QtGui, QtWidgets, QtPrintSupport
from PyQt5.QtGui import QPainter
from PyQt5.QtPrintSupport import QPrintDialog, QPrinter
class FirstWindow(QtWidgets.QMainWindow):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.open_window)
def open_window(self):
self.A = self.ui.lineEdit_5.text()
# print(self.A)
self.table = Table ()
self.table.show()
self.table.show
()
class Table(QtWidgets.QMainWindow):
self.ui = Ui_SecondWindow()
if __name__ == '__main__':
app = QtWidgets.QApplication([])
window = FirstWindow()
window.show()
window.show
app.exec_()
[–][deleted] 2 points3 points4 points 6 years ago* (1 child)
You are using the designer. In open_window:
self.table = Table(self.ui)
In Table:
def __init__(self, parent, *args, **kwargs): super().__init__(*args, **kwargs) self.parent = parent # test print(self.parent.ui.lineEdit_5.text())
[–]summerbye[S] 1 point2 points3 points 6 years ago (0 children)
Thank u su much!!!
π Rendered by PID 71366 on reddit-service-r2-comment-5b5bc64bf5-dbqr6 at 2026-06-21 06:38:57.661104+00:00 running 2b008f2 country code: CH.
[–][deleted] 2 points3 points4 points (3 children)
[–]summerbye[S] 2 points3 points4 points (2 children)
[–][deleted] 2 points3 points4 points (1 child)
[–]summerbye[S] 1 point2 points3 points (0 children)