Accessing and Editing UI Elements between Different Classes in PyQT5 - python

I am in the process of writing code that generates a main 'TopLevel' window where information is entered and then, upon the click of a pushbutton, another window opens and this information is sent through and accessed/edited/interacted with in that window. I have seemingly tried every way I can find on this website and others to try to access ui elements (be they labels, text inputs or, in this specific case, a dictionary) between different classes and nothing has worked so far.
I've edited the code below so that all the relevant elements are available and this version runs up to the point that the error is produced. The user types whatever they want in the box underneath "Input dictionary elements", clicks "Done" to add it to the list underneath "List of dictionary elements" and can then press "Expand" under the leftmost box to open the second window that I want to pass the list to.
import sys
from PyQt5 import uic
from PyQt5.QtWidgets import QApplication, QMainWindow, QWidget, QDesktopWidget, QMessageBox, QPushButton, QAction, qApp, QMenu, QLineEdit, QLabel, QTextEdit, QComboBox, QScrollArea, QVBoxLayout, QScrollBar, QListWidget
from PyQt5.QtGui import QFont, QIcon
from PyQt5.QtCore import pyqtSlot, QCoreApplication, QMetaObject, QRect
def setKey(dictionary, key, value):
if key not in dictionary:
dictionary[key] = value
elif type(dictionary[key]) == list:
dictionary[key].append(value)
else:
dictionary[key] = [dictionary[key], value]
class TopLevel(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle('Top Level')
self.resize(800,550)
topLevelLabel = QLabel(self)
topLevelLabel.setText('Top level of tree')
self.topLevelBox = QTextEdit(self)
self.topLevelBox.resize(200,50)
self.topLevelBox.move(60,100)
topLevelLabel.move(60,70)
topLevelExpandButton = QPushButton('Expand', self)
topLevelExpandButton.resize(50,30)
topLevelExpandButton.move(100,150)
topLevelExpandButton.pressed.connect(self.open_New_Window_Expand)
selectSCLabel = QLabel(self)
selectSCLabel.setText('Input dictionary elements')
self.selectSCBox = QTextEdit(self)
self.selectSCBox.resize(300,50)
self.selectSCBox.move(300,100)
selectSCLabel.move(300,60)
selectSCLabel.resize(400,50)
selectSCConfirmationButton = QPushButton('Done', self)
selectSCConfirmationButton.resize(40,30)
selectSCConfirmationButton.move(560,150)
selectSCConfirmationButton.pressed.connect(self.selectSCConfirmationButtonPressed)
listOfSelectedSCLabel = QLabel(self)
listOfSelectedSCLabel.setText('List of dictionary elements')
listOfSelectedSCLabel.setWordWrap(True)
listOfSelectedSCLabel.move(60,190)
listOfSelectedSCLabel.resize(200,30)
self.listOfSelectedSCArea = QScrollArea(self)
self.placeholderListItem = QWidget()
self.vboxOfListItems = QVBoxLayout()
self.listOfSelectedSCArea.move(60,220)
self.listOfSelectedSCArea.resize(200,300)
self.listOfSelectedSCArea.setVerticalScrollBarPolicy(0)
self.listOfSelectedSCArea.setHorizontalScrollBarPolicy(0)
self.listOfSelectedSCArea.setWidgetResizable(True)
self.listOfSelectedSCDictionary = {}
self.SCIterate = 1
self.show()
def open_New_Window_Expand(self):
self.new_window = QMainWindow
self.ui = NewLevelExpand()
self.show()
def selectSCConfirmationButtonPressed(self):
newSCName = self.selectSCBox.toPlainText()
nameToLabel = QLabel(self)
nameToLabel.setText(newSCName)
self.vboxOfListItems.addWidget(nameToLabel)
self.placeholderListItem.setLayout(self.vboxOfListItems)
self.listOfSelectedSCArea.setWidget(self.placeholderListItem)
setKey(self.listOfSelectedSCDictionary, self.SCIterate, newSCName)
self.SCIterate = self.SCIterate + 1
print(self.listOfSelectedSCDictionary)
class NewLevelExpand(TopLevel):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self, parent = TopLevel):
self.setWindowTitle('Expanded Level')
self.resize(800,550)
print(self.listOfSelectedSCDictionary)
self.show()
def main():
app = QApplication(sys.argv)
tl = TopLevel()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
With tinkering with this code, I have generated numerous different error messages but the code above produces the message: "AttributeError: 'NewLevelExpand' object has no attribute 'listOfSelectedSCDictionary'"
As I say, I feel I have tried everything relating to this topic on stackoverflow and nothing has worked. Any advice and guidance, pointing out stupid errors, suggestions to changing my coding style to make it clearer, etc. would be massively appreciated.

Premise: I cannot help you a lot with the logic behind your program; I've to admit, it's a bit confused, and I don't understand how you're going to pass data to the new window, nor how you are going to use it.
The error you're facing is because NewLevelExpand is a subclass of TopLevel, and when you call its super().__init__() this results in calling the ancestor's __init__().
In the TopLevel class, __init__() calls initUI, which creates the whole UI and the listOfSelectedSCDictionary dictionary.
The problem is that you are overriding initUI in the subclass, so the result is that the base class initUI is never called (meaning that the UI nor the dictionary are actually created).
The solution to this specific problem is to call the base class implementation of initUI in the subclass:
class NewLevelExpand(TopLevel):
# ...
def initUI(self):
super().initUI()
self.setWindowTitle('Expanded Level')
self.resize(800,550)
print(self.listOfSelectedSCDictionary)

Related

The program just stops running once i click the signinButton and exits with Process finished with exit code -1073740791 (0xC0000409)

from PyQt6.QtWidgets import (
QMainWindow, QApplication, QDialog, QDialogButtonBox, QLabel, QTextEdit, QPushButton, QMessageBox, QMdiArea,
QTableWidgetItem, QStackedWidget
)
from PyQt6 import uic
import sys
class UI(QMainWindow):
def __init__(self):
super(UI, self).__init__()
uic.loadUi(r"C:\Users\csc\Documents\Rentour\front.ui", self)
self.show()
# define widgets
self.button = self.findChild(QPushButton, "signinButton")
self.signinButton.clicked.connect(self.OpenSignUp)
def OpenSignUp(self):
Sign_Up = Second()
widget.addWidget(Sign_Up)
widget.setCurrentIndex(widget.currentIndex()+1)
class Second(QMainWindow):
def __init__(self):
super(Second, self).__init__()
uic.loadUi(r"C:\Users\csc\Documents\Rentour\signpopup.ui", self)
# define widgets
self.button = self.findChild(QPushButton, "SubmitSignButton")
self.SubmitSignButton.clicked.connect(self.SignUpSave)
def SignUpSave(self):
email =self.EmailLine.text()
phoneno =self.PhonenoLine.text()
name =self.NameLine.text()
password = self.PasswordLine.text()
print(password)
app = QApplication(sys.argv)
mainwindow = UI()
widget = QStackedWidget()
widget.addWidget(mainwindow)
widget.show()
app.exec()
this is my code. Am trying to create a login/signup page. So when i click the signinButton, i want it to load the ui for the page which will have a bunch of line edits whose inputs im attempting to store in variables.
The ui files were made using qt designer and and i made this file from scratch. I also referred code with Hala(Youtuber). I Am trying to create a login/signup page. So when i click the signinButton, i want it to load the ui for the page which will have a bunch of line edits whose inputs im attempting to store in variables.
The problem is in your OpenSignUp function. The line widget.addWidget(Sign_Up) is not a valid command for a couple of reasons.
Also Sign_Up varable is holding a newly constructed QMainWindow, which are meant to be top level widgets and shouldn't be added to a layout.
It isn't totally clear what you are trying to achieve, but I am going to assume that you are trying to launch a secondary sign in window, In which case you want to use the open() method to launch the new window.
For example:
def OpenSignUp(self):
self.Sign_Up = Second()
self.Sign_Up.open()
Since you are using a stacked widget it is also possible that your goal is to simply switch to a different widget in the same window. In which case your Second class should probably just be a standard QWidget, and not a QMainWindow. and your stacked widget should be set as the central widget of your UI class.
So that would probably look something like this:
from PyQt6.QtWidgets import (
QMainWindow, QApplication, QDialog, QDialogButtonBox, QLabel, QTextEdit, QPushButton, QMessageBox, QMdiArea,
QTableWidgetItem, QStackedWidget
)
from PyQt6 import uic
import sys
class UI(QMainWindow):
def __init__(self):
super(UI, self).__init__()
# uic.loadUi(r"C:\Users\csc\Documents\Rentour\front.ui", self)
self.widget = QStackedWidget()
self.widget.addWidget(mainwindow)
self.setCentralWidget(self.widget)
self.Sign_Up = Second()
self.widget.addWidget(self.Sign_Up)
# define widgets
self.button = self.findChild(QPushButton, "signinButton")
self.signinButton.clicked.connect(self.OpenSignUp)
def OpenSignUp(self):
self.widget.setCurrentIndex(widget.currentIndex()+1)
class Second(QWidget):
def __init__(self):
super(Second, self).__init__()
uic.loadUi(r"C:\Users\csc\Documents\Rentour\signpopup.ui", self)
# define widgets
self.button = self.findChild(QPushButton, "SubmitSignButton")
self.SubmitSignButton.clicked.connect(self.SignUpSave)
def SignUpSave(self):
email =self.EmailLine.text()
phoneno =self.PhonenoLine.text()
name =self.NameLine.text()
password = self.PasswordLine.text()
print(password)
app = QApplication(sys.argv)
mainwindow = UI()
mainwindow.show()
app.exec()
Except you will need to rearrange the .ui file for UI class so that it is applied on top of the stacked widget as well.

How to implement an interactive QAction with Pyside ? (i.e. How to catch event in a QAction ?)

It might be a very simple question but I can't figure out how to do it.
The context:
I am making an application that can draw polygons in a QGraphicsScene. I would like to implement interactive actions. For example, the user clicks on a button, then clicks on the scene to draw temporary lines, finally the app cuts the polygon with the line.
What I try to achieve
What I did
Since I didn't find anything here or in the doc, I looked in the LibreCad repository to know how they do it.
https://github.com/LibreCAD/LibreCAD/blob/768285653c46e734a75460928142cda1a33c2c53/librecad/src/lib/actions/rs_actioninterface.h
Their base class inherits from QObject to handle events. It seems that they don't inherit from QAction despite line 40 where one can read "class QAction;". My C++ skills end here.
In an act of faith, I wrote the following minimal non-working example in python with PySide.
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
from PySide2.QtCore import QObject
from PySide2.QtWidgets import (QApplication, QMainWindow, QWidget,
QGraphicsView, QGraphicsScene,
QToolBar, QAction)
class Action(QAction, QObject):
def __init__(self, name, parent=None):
super().__init__(name, parent)
# I also tried to add this, obviously I don't know what I am doing
#QObject.__init__(parent)
def keyPressEvent(self, event):
print("Event handled")
super().keyPressEvent(event)
class MainWindow(QMainWindow,):
def __init__(self):
super(MainWindow, self).__init__()
self.centralwidget = QWidget()
self.graphicsView = QGraphicsView(self.centralwidget)
self.setCentralWidget(self.centralwidget)
self.scene = QGraphicsScene(0,0,1000,1000)
self.graphicsView.setScene(self.scene)
toolbar = QToolBar("My toolbar")
self.addToolBar(toolbar)
knifeActionButton = Action("Knife", self)
knifeActionButton.setShortcut("K")
knifeActionButton.triggered.connect(self.cutPolygon)
toolbar.addAction(knifeActionButton)
def cutPolygon(self):
print("Action triggered")
if __name__ == '__main__':
app = QApplication(sys.argv)
w = MainWindow()
w.show()
app.exec_()
The question:
How to handle events in a QAction to make it interactive?
Please excuse my English, I am a non-native speaker

PyQt5 Memory Management

I would like to understand how Python's and PyQt's garbage collectors work. In the following example, I create a QWidget (named TestWidget) that has a python attribute 'x'. I create TestWidget, interact with it, then close its window. Since I have set WA_DeleteOnClose, this should signal the Qt event loop to destroy my instance of TestWidget. Contrary to what I expect, at this point (and even after the event loop has finished) the python object referenced by TestWidget().x still exists.
I am creating an app with PyQt where the user opens and closes many many widgets. Each widget has attributes that take up a substantial amount of memory. Thus, I would like to garbage collect (in both Qt and Python) this widget and its attributes when the user closes it. I have tried overriding closeEvent and deleteEvent to no success.
Can someone please point me in the right direction? Thank you! Example code below:
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QTextEdit
from PyQt5.QtCore import Qt
class TestWidget(QWidget):
def __init__(self, parent, **kwargs):
super().__init__(parent, **kwargs)
self.setAttribute(Qt.WA_DeleteOnClose)
self.widget = None
self.x = '1' * int(1e9)
def load(self):
layout = QVBoxLayout(self)
self.widget = QTextEdit(parent=self)
layout.addWidget(self.widget)
self.setLayout(layout)
if __name__ == '__main__':
from PyQt5.QtWidgets import QApplication
import gc
app = QApplication([])
widgets = []
widgets.append(TestWidget(parent=None))
widgets[-1].load()
widgets[-1].show()
widgets[-1].activateWindow()
app.exec()
print(gc.get_referrers(gc.get_referrers(widgets[-1].x)[0]))
An important thing to remember is that PyQt is a binding, any python object that refers to an object created on Qt (the "C++ side") is just a wrapper.
The WA_DeleteOnClose only destroys the actual QWidget, not its python object (the TestWidget instance).
In your case, what's happening is that Qt releases the widget, but you still have a reference on the python side (the element in your list): when the last line is executed, the widgets list and its contents still exist in that scope.
In fact, you can try to add the following at the end:
print(widgets[-1].objectName())
And you'll get the following exception:
Exception "unhandled RuntimeError"
wrapped C/C++ object of type TestWidget has been deleted
When also the python object is deleted, then all its attributes are obviously deleted as well.
To clarify, see the following:
class Attribute(object):
def __del__(self):
print('Deleting Attribute...')
class TestWidget(QWidget):
def __init__(self, parent, **kwargs):
super().__init__(parent, **kwargs)
self.setAttribute(Qt.WA_DeleteOnClose)
self.widget = None
self.x = Attribute()
def load(self):
layout = QVBoxLayout(self)
self.widget = QTextEdit(parent=self)
layout.addWidget(self.widget)
self.setLayout(layout)
def __del__(self):
print('Deleting TestWidget...')
You'll see that __del__ doesn't get called in any case with your code.
Actual deletion will happen if you add del widgets[-1] instead.
Explanation
To understand the problem, you must know the following concepts:
Python objects are eliminated only when they no longer have references, for example in your example when adding the widget to the list then a reference is created, another example is that if you make an attribute of the class then a new reference is created.
PyQt (and also PySide) are wrappers of the Qt library (See 1 for more information), that is, when you access an object of the QFoo class from python, you do not access the C++ object but the handle of that object. For this reason, all the memory logic that Qt creates is handled by Qt but those that the developer creates has to be handled by himself.
Considering the above, what the WA_DeleteOnClose flag does is eliminate the memory of the C++ object but not the python object.
To understand how memory is being handled, you can use the memory-profiler tool with the following code:
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QTextEdit
from PyQt5.QtCore import Qt, QTimer
from PyQt5 import sip
class TestWidget(QWidget):
def __init__(self, parent, **kwargs):
super().__init__(parent, **kwargs)
self.setAttribute(Qt.WA_DeleteOnClose)
self.widget = None
self.x = ""
period = 1000
QTimer.singleShot(4 * period, self.add_memory)
QTimer.singleShot(8 * period, self.close)
QTimer.singleShot(12 * period, QApplication.quit)
def load(self):
layout = QVBoxLayout(self)
self.widget = QTextEdit()
layout.addWidget(self.widget)
def add_memory(self):
self.x = "1" * int(1e9)
if __name__ == "__main__":
from PyQt5.QtWidgets import QApplication
import gc
app = QApplication([])
app.setQuitOnLastWindowClosed(False)
widgets = []
widgets.append(TestWidget(parent=None))
widgets[-1].load()
widgets[-1].show()
widgets[-1].activateWindow()
app.exec()
In the previous code, in second 4 the memory of "x" is created, in second 8 the C++ object is eliminated but the memory associated with "x" is not eliminated and this is only eliminated when the program is closed since it is clear the list and hence the python object reference.
Solution
In this case a possible solution is to use the destroyed signal that is emitted when the C++ object is deleted to remove all references to the python object:
from PyQt5.QtWidgets import QWidget, QVBoxLayout, QTextEdit
from PyQt5.QtCore import Qt, QTimer
from PyQt5 import sip
class TestWidget(QWidget):
def __init__(self, parent=None):
super().__init__(parent)
self.setAttribute(Qt.WA_DeleteOnClose)
self.widget = None
self.x = ""
period = 1000
QTimer.singleShot(4 * period, self.add_memory)
QTimer.singleShot(8 * period, self.close)
QTimer.singleShot(12 * period, QApplication.quit)
def load(self):
layout = QVBoxLayout(self)
self.widget = QTextEdit()
layout.addWidget(self.widget)
def add_memory(self):
self.x = "1" * int(1e9)
class Manager:
def __init__(self):
self._widgets = []
#property
def widgets(self):
return self._widgets
def add_widget(self, widget):
self._widgets.append(widget)
widget.destroyed.connect(self.handle_destroyed)
def handle_destroyed(self):
self._widgets = [widget for widget in self.widgets if not sip.isdeleted(widget)]
if __name__ == "__main__":
from PyQt5.QtWidgets import QApplication
app = QApplication([])
app.setQuitOnLastWindowClosed(False)
manager = Manager()
manager.add_widget(TestWidget())
manager.widgets[-1].load()
manager.widgets[-1].show()
manager.widgets[-1].activateWindow()
app.exec()

Sending Data from Child to Parent Window in PyQt5

What I can't do
I'm not able to send data back from a child to a parent window.
What I have
I've got a complex GUI with several windows sendíng data to child windows. Each window represents a unique Python-script in the same directory. There was no need to explicitely specify parents and childs, as the communication was always unidirectional (parent to child). However, now I need to send back data from childs to parents and can't figure out how to do this as each window (i.e. each class) has its own file.
Example
Here's a minimal example showing the base of what I want to accomplish.
What it does: win01 opens win02 and win02 triggers func in win01.
# testfile01.py
import sys
from PyQt5.QtWidgets import *
import testfile02 as t02
class win01(QWidget):
def __init__(self, parent=None):
super(win01, self).__init__(parent)
self.win02 = t02.win02()
self.button = QPushButton("open win02", self)
self.button.move(100, 100)
self.button.clicked.connect(self.show_t02)
def initUI(self):
self.center
def show_t02(self):
self.win02.show()
def func(self):
print("yes!")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = win01()
ex.show()
sys.exit(app.exec_())
##########################################################################
# testfile02.py
from PyQt5.QtWidgets import *
import testfile01 as t01
class win02(QWidget):
def __init__(self, parent=None):
super(win02, self).__init__(parent)
self.win01 = t01.win01()
self.button = QPushButton()
self.button.clicked.connect(self.win01.func)
def initUI(self):
self.center()
What I tried
Importing testfile01 in the second window always leads to the error:
RecursionError: maximum recursion depth exceeded.
Then, I tried the following approaches, but they didn't work either:
Not importing testfile01 in win02 and adjusting parent=None to different other objects
Importing testfile01 within the __init__ call of win02
Creating a signal in win02 to trigger func in win01
The Question
Is there a solution how to properly trigger func in win01 from win02?
Why are you getting RecursionError: maximum recursion depth exceeded?
You are getting it because you have a circular import that generates an infinite loop, in testfile01 you are importing the file testfile02, and in testfile02 you are importing testfile01, .... So that is a shows of a bad design.
Qt offers the mechanism of signals for objects to communicate information to other objects, and this has the advantage of non-dependence between classes that is a great long-term benefit (as for example that avoids circular import), so for that reason I think it is the most appropriate.
For this I will create the clicked signal in the class win02 that will be triggered by the clicked signal of the button, and make that clicked signal call the func:
testfile01.py
import sys
from PyQt5.QtWidgets import QWidget, QPushButton, QApplication
import testfile02 as t02
class win01(QWidget):
def __init__(self, parent=None):
super(win01, self).__init__(parent)
self.win02 = t02.win02()
self.win02.clicked.connect(self.func)
self.button = QPushButton("open win02", self)
self.button.move(100, 100)
self.button.clicked.connect(self.show_t02)
def show_t02(self):
self.win02.show()
def func(self):
print("yes!")
if __name__ == "__main__":
app = QApplication(sys.argv)
ex = win01()
ex.show()
sys.exit(app.exec_())
testfile02.py
from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QWidget, QPushButton, QVBoxLayout
class win02(QWidget):
clicked = pyqtSignal()
def __init__(self, parent=None):
super(win02, self).__init__(parent)
self.button = QPushButton("call to func")
self.button.clicked.connect(self.clicked)
lay = QVBoxLayout(self)
lay.addWidget(self.button)
I recommend you read:
https://doc.qt.io/qt-5/signalsandslots.html
Both the Widgets are independent and have no link in between.
Set win01 parent of win02.
In class win01
Replace :
self.win01 = t02.win02()
#and
self.win02.show()
with:
self.win01 = t02.win02(self)
#and
self.win01.show()
and in class win02
Replace:
self.win02 = t01.win01()
#and
self.button.clicked.connect(self.win01.func)
with:
self.win02 = self.parent()
#and
self.button.clicked.connect(self.win02.func)

How to access childs of One Layout from another child of other layout in PyQt5?

First, please let me explain the situation.
I have a QVBoxLayout, which contains two QHBoxLayout, one of them has a QLineEdit and a QPushButton, another has a single QLabel, which should be filled with the text of QLineEdit when button is pressed. That's it.
I know, how to handle buttonClicked event, how to get the value of QEditText and all that.
The main problem here is, how do I access the QLabel and QLineEdit instance inside the buttonClicked event handler, specially when they are child of separate BoxLayout.
I have already solved this problem by defining them as class variables, so can access them from anywhere. But this is not a good design apparently. So, I am looking for a recommended way to solve this particular problem.
My Code:
import sys
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QHBoxLayout, QLabel, QWidget, QPushButton, QLineEdit
class Example(QWidget):
def __init__(self):
super().__init__()
self.setUI()
def setUI(self):
h1box = QHBoxLayout()
line_edit = QLineEdit()
button = QPushButton("Submit")
button.clicked.connect(self.buttonClicked)
h1box.addWidget(line_edit)
h1box.addWidget(button)
h2box = QHBoxLayout()
label = QLabel("0")
h2box.addWidget(label)
vbox = QVBoxLayout()
vbox.addLayout(h1box)
vbox.addLayout(h2box)
self.setLayout(vbox)
self.show()
def buttonClicked(self):
# label needs to be filled with LineEdit value
app = QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_())
You seem to be confusing the terms class variable and instance variable.
The former is an attribute of the class, and is potentially shared between all instances of the class; whereas the latter is an attribute of the instance, and is normally unique to each instance. A class attribute can be accessed directly via the class object itself (meaning it is usually available in the global namespace); whereas an instance attribute must be accessed via a specific instance (and thus is not normally globally available).
In PyQt/PySide applications, it is completely normal and accepted practice to use instance variables. Pretty much every example and tutorial you will see uses them, and that is what you should also use to solve your own current problem.
Class variables are most commonly used as global constants. So for example in Qt there are many enums that are accessible via the class (e.g. QPalette.Background). If you've read that defining class variables is bad design, it's probably in the context of using them as global state variables - which is generally considered to be bad practice in most programming languages.
Sir, there are a million ways of doing that. I don't know if you want in this way, but here is a little example.
import sys
from PyQt5.QtWidgets import QApplication, QVBoxLayout, QHBoxLayout, QLabel, QWidget, QPushButton, QLineEdit
class Example(QWidget):
line_edit = None
button = None
h1box = None
h2box = None
vbox = None
label = None
def __init__(self):
super().__init__()
self.setUI()
def setUI(self):
self.h1box = QHBoxLayout()
self.line_edit = QLineEdit()
self.button = QPushButton("Submit")
self.button.clicked.connect(self.buttonClicked)
self.h1box.addWidget(self.line_edit)
self.h1box.addWidget(self.button)
self.h2box = QHBoxLayout()
self.label = QLabel("0")
self.h2box.addWidget(self.label)
self.vbox = QVBoxLayout()
self.vbox.addLayout(self.h1box)
self.vbox.addLayout(self.h2box)
self.setLayout(self.vbox)
self.show()
def buttonClicked(self):
self.label.setText(self.line_edit.text())
pass
if __name__ == '__main__':
app = QApplication(sys.argv)
exemp = Example()
exemp.showMaximized()
sys.exit(app.exec_())

Categories

Resources