Edits: Phrasing and included a minimum reproducible example
I have a question about how object names work in PyQt5 / how OOP works in PyQt5:
Background
I'm working on a project which includes a QTabWidget. This QTabWidget adds a new tab each time a '+' tab is clicked:
Before click:
After click:
When I add the new tab as just a blank widget using insertNewRegionTab(), everything works properly; however, when I instead use a custom class that is a derived class of QtWidgets.QWidget (customTab), the program crashes. I created this class so that each tab would have the same formatting / internal relationships between objects, and that I could just add as many as I needed with the '+' button.
I think the crashing may be due to name conflicts, e.g. a label called "label1" being created in two tabs simultaneously.
Question
The problem is that I don't see how name conflicts could be an issue if each customTab is it's own object. I'm wondering if any one knows why I can't implement this customTab class in the desired way.
Proposed Solution
My thoughts on a solution is to just define class counters and then increment every time a new tab is added so they all have unique names, but this is a bit of work so I wanted to make sure that this is actually what the problem is before I implement it.
Code
N.B. - The two original tabs using this code will not have names. The one on the left, 'Test 1', has a combo box in it and is in the customTab class. The one on the right, '+', adds a new tab, but a normal QWidget instead of customTab object
from PyQt5 import QtCore, QtGui, QtWidgets
class topLevelWindow(QtWidgets.QMainWindow):
def __init__(self):
# Function that is used to add tabs
def insertNewRegionTab(self):
if self.mainTabWidgetCount == 1 + self.mainTabWidget.currentIndex():
# Attempted method 1:
tab = QtWidgets.QWidget() # Want this to be a customTab not a QWidget
self.mainTabWidget.insertTab(self.mainTabWidget.currentIndex(),
tab, "Tab " + str(self.mainTabWidgetCount))
# Attempted method 2:
# self.tabInstaces.append(customTab(self.mainTabWidget))
self.mainTabWidgetCount += 1
super().__init__()
# Initialization of main window
self.setObjectName("MainWindow")
self.resize(500, 300)
self.centralwidget = QtWidgets.QWidget(self)
self.centralwidget.setObjectName("centralwidget")
self.gridLayout_5 = QtWidgets.QGridLayout(self.centralwidget)
self.gridLayout_5.setObjectName("gridLayout_5")
# Create the main tab widget and set properties
self.mainTabWidget = QtWidgets.QTabWidget(self.centralwidget)
self.mainTabWidget.setObjectName("mainTabWidget")
self.mainTabWidget.setCurrentIndex(0)
self.gridLayout_5.addWidget(self.mainTabWidget, 1, 1, 1, 1)
self.setCentralWidget(self.centralwidget)
# Insert a tab (of the custom, pre-formatted tab class) into this tab widget
self.tabInstances = [customTab(self.mainTabWidget)]
self.mainTabWidgetCount = 2
# Add the tab which creates other tabs to the tan widget
self.addRegionTab = QtWidgets.QWidget()
self.addRegionTab.setObjectName("addRegionTab")
self.mainTabWidget.addTab(self.addRegionTab, "")
# Add functionality: When '+' tab is selected, add a tab
self.mainTabWidget.currentChanged.connect(lambda: insertNewRegionTab(self))
# Show window
self.show()
class customTab(QtWidgets.QWidget):
def __init__(self, parent=None):
# Initializes the object itself and renames it. Add vertical layout to it
super(customTab, self).__init__()
self.setObjectName("tabInstances")
self.verticalLayout = QtWidgets.QVBoxLayout(self)
self.verticalLayout.setObjectName("verticalLayout")
self.comboBox1 = QtWidgets.QComboBox(self)
self.comboBox1.setObjectName("comboBox1")
self.comboBox1.addItem("")
self.comboBox1.addItem("")
# Add self to parent
parent.addTab(self, "")
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = topLevelWindow()
sys.exit(app.exec_())
I do not understand the logic of OP since it asks about objectName() that has nothing to do with the problem, the objectName is only a name that allows us to identify elements and nothing else.
In my answer I show how to create the button that when pressing must add tabs:
from PyQt5 import QtCore, QtGui, QtWidgets
class TabWidget(QtWidgets.QTabWidget):
plusClicked = QtCore.pyqtSignal()
def __init__(self, parent=None):
super().__init__(parent)
self.tabBar().installEventFilter(self)
self.add_button = QtWidgets.QToolButton(self, text="+")
self.add_button.clicked.connect(self.plusClicked)
def eventFilter(self, obj, event):
if obj is self.tabBar() and event.type() == QtCore.QEvent.Resize:
r = self.tabBar().geometry()
h = r.height()
self.add_button.setFixedSize((h - 1) * QtCore.QSize(1, 1))
self.add_button.move(r.right(), 0)
return super().eventFilter(obj, event)
class topLevelWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
# Initialization of main window
self.setObjectName("MainWindow")
self.resize(500, 300)
self.centralwidget = QtWidgets.QWidget(self)
self.setCentralWidget(self.centralwidget)
lay = QtWidgets.QGridLayout(self.centralwidget)
# Create the main tab widget and set properties
self.mainTabWidget = TabWidget()
self.mainTabWidget.setObjectName("mainTabWidget")
self.mainTabWidget.setCurrentIndex(0)
lay.addWidget(self.mainTabWidget, 1, 1, 1, 1)
self.mainTabWidget.addTab(CustomWidget(), "Tab1")
self.mainTabWidget.plusClicked.connect(self.add_clicked)
def add_clicked(self):
index = self.mainTabWidget.count() + 1
self.mainTabWidget.addTab(CustomWidget(), "Tab {}".format(index))
class CustomWidget(QtWidgets.QWidget):
def __init__(self, parent=None):
# Initializes the object itself and renames it. Add vertical layout to it
super(CustomWidget, self).__init__(parent)
self.comboBox1 = QtWidgets.QComboBox()
self.comboBox1.addItems(list("abcdef"))
lay = QtWidgets.QVBoxLayout(self)
lay.addWidget(self.comboBox1)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = topLevelWindow()
w.show()
sys.exit(app.exec_())
Related
This question already has answers here:
PyQT Navigation between layouts
(2 answers)
Closed 1 year ago.
How to get back my MainWindow ?
From my MainWindow. If I Press either the "Open Left Box" button or "Open Right Box" button, it's worked and at the same time, If I press the "Back" Button from Left Box, nothing will happen. How to obtain the main window? (Simply, I want to know how to set Layouts and remove layouts in setcentral Widgets)
import sys,os
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
class Class_MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("Main Window")
self.initUI()
def initUI(self):
self.widgets()
self.layouts()
def widgets(self):
self.Masterbtn = QPushButton("Master")
self.transbtn = QPushButton("tanscation")
self.reportbtn = QPushButton("Reports")
self.masterlbl = QLabel("Master Label")
self.translbl = QLabel("transcation label")
self.reportlbl = QLabel("Report Label")
self.leftboxbtn = QPushButton("Open Left Box")
self.leftboxbtn.clicked.connect(self.leftboxopn)
self.rightboxbtn = QPushButton("Open Right Box")
self.rightboxbtn.clicked.connect(self.rightboxopn)
self.backbtn =QPushButton("Back")
self.backbtn.clicked.connect(self.mainwindow)
def layouts(self):
self.mainbox = QVBoxLayout()
self.mainbox.addWidget(self.leftboxbtn)
self.mainbox.addWidget(self.rightboxbtn)
self.leftbox = QVBoxLayout()
self.leftbox.addWidget(self.Masterbtn)
self.leftbox.addWidget(self.transbtn)
self.leftbox.addWidget(self.reportbtn)
self.leftbox.addWidget(self.backbtn)
self.rightbox = QVBoxLayout()
self.rightbox.addWidget(self.masterlbl)
self.rightbox.addWidget(self.translbl)
self.rightbox.addWidget(self.reportlbl)
# self.rightbox.addWidget(self.backbtn)
widget = QWidget()
widget.setLayout(self.mainbox)
self.setCentralWidget(widget)
def leftboxopn(self):
self.setWindowTitle("Left Box ")
widget = QWidget()
widget.setLayout(self.leftbox)
self.setCentralWidget(widget)
def rightboxopn(self):
self.setWindowTitle("Right Box")
widget = QWidget()
widget.setLayout(self.rightbox)
self.setCentralWidget(widget)
def mainwindow(self):
self.setWindowTitle("Main Window")
widget = QWidget()
widget.setLayout(self.mainbox)
self.setCentralWidget(widget)
def main():
app = QApplication(sys.argv)
mainwindow = Class_MainWindow()
mainwindow.show()
sys.exit(app.exec_())
if __name__ =="__main__":
main()
You cannot "get back" anything, because everytime you use setCentralWidget() the existing widget gets deleted, as the documentation explains:
Note: QMainWindow takes ownership of the widget pointer and deletes it at the appropriate time.
When you call setCentralWidget() on another widget, the previous is completely deleted, including all its children. When a Qt object is deleted, all its child objects gets deleted along with it, and the result is that the self.mainbox you created in the beginning doesn't exist any more (the python object exists, but remember that PyQt objects are only a reference to the actual Qt objects: a Qt object can be deleted if Qt requires it, even if the python reference still exists).
In substance (and, in any case), you should not replace the central widget everytime, but use a paged widget like QStackedWidget as the central widget instead, and then switch to the other interfaces using its functions: setCurrentIndex() or setCurrentWidget().
In order to properly use it, all child widgets must be added to a QWidget container, which will then be added as individual "pages" to QStackedWidget:
class Class_MainWindow(QMainWindow):
# ...
def layouts(self):
self.mainContainer = QWidget()
self.mainbox = QVBoxLayout(self.mainContainer)
self.mainbox.addWidget(self.leftboxbtn)
self.mainbox.addWidget(self.rightboxbtn)
self.leftContainer = QWidget()
self.leftbox = QVBoxLayout(self.leftContainer)
self.leftbox.addWidget(self.Masterbtn)
self.leftbox.addWidget(self.transbtn)
self.leftbox.addWidget(self.reportbtn)
self.leftbox.addWidget(self.backbtn)
self.rightContainer = QWidget()
self.rightbox = QVBoxLayout(self.rightContainer)
self.rightbox.addWidget(self.masterlbl)
self.rightbox.addWidget(self.translbl)
self.rightbox.addWidget(self.reportlbl)
# self.rightbox.addWidget(self.backbtn)
self.stackedWidget = QStackedWidget()
self.setCentralWidget(self.stackedWidget)
self.stackedWidget.addWidget(self.mainContainer)
self.stackedWidget.addWidget(self.leftContainer)
self.stackedWidget.addWidget(self.rightContainer)
def leftboxopn(self):
self.setWindowTitle("Left Box ")
self.stackedWidget.setCurrentWidget(self.leftContainer)
def rightboxopn(self):
self.setWindowTitle("Right Box")
self.stackedWidget.setCurrentWidget(self.rightContainer)
def mainwindow(self):
self.setWindowTitle("Main Window")
self.stackedWidget.setCurrentWidget(self.mainContainer)
I am trying to make a list box where a user can enter more items to the list. I have a list box set up with an add button. The add button opens up a user input box where it will direct the user to enter a value. However, I am have issue with passing on the value of user input to the add onto the list. Any suggestions would help. Below is my code:
List box
from input_box import *
class list_form(QtGui.QWidget):
def __init__(self,list_of_items,open_text,parent= None):
super(list_form, self).__init__()
global output_path
output_path = output_path_i
grid = QtGui.QGridLayout()
grid.setSpacing(10)
self.widget = QtGui.QWidget()
self.layout = QtGui.QGridLayout(self.widget)
open_message = QtGui.QLabel(open_text)
grid.addWidget(open_message,0,0,2,4)
self.lst = QtGui.QListWidget()
grid.addWidget(self.lst,3, 0,1,4)
for i in list_of_items:
self.lst.addItem(str(i))
self.setLayout(grid)
add = QtGui.QPushButton('Add')
grid.addWidget(add,50,0)
add.clicked.connect(self.add_button)
def add_button(self):
self.input_box = input_box()
self.input_box.setWindowTitle("Window 2")
self.input_box.show()
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
window = list_form(list(xrange(100)),"List of Values")
window.setWindowTitle('Window 1')
window.show()
sip.setdestroyonexit(False)
sys.exit(app.exec_())
Input box
import sys
from PyQt4 import QtCore, QtGui
import sip
class input_box(QtGui.QWidget):
def __init__(self,parent= None):
super(input_box, self).__init__()
grid = QtGui.QGridLayout()
grid.setSpacing(10)
self.widget = QtGui.QWidget()
self.layout = QtGui.QGridLayout(self.widget)
open_message = QtGui.QLabel("Enter Value:")
grid.addWidget(open_message,0,0,2,3)
self.txt = QtGui.QLineEdit()
grid.addWidget(self.txt,2, 0,1,2)
self.setLayout(grid)
save = QtGui.QPushButton('Save')
grid.addWidget(save,50,0)
a = save.clicked.connect(self.save)
save.clicked.connect(self.close)
cancel = QtGui.QPushButton('Cancel')
grid.addWidget(cancel,50,1)
cancel.clicked.connect(self.close)
def save(self):
value = self.txt.text()
return value
If you want to get data from a window you should use a QDialog instead of a QWidget, connect the clicked signal of save and cancel to the accept and reject slot, respectively:
input_box.py
from PyQt4 import QtCore, QtGui
class Input_Box(QtGui.QDialog):
def __init__(self,parent= None):
super(Input_Box, self).__init__(parent)
open_message = QtGui.QLabel("Enter Value:")
self.txt = QtGui.QLineEdit()
save = QtGui.QPushButton('Save', clicked=self.accept)
cancel = QtGui.QPushButton('Cancel', clicked=self.reject)
grid = QtGui.QGridLayout(self)
grid.setSpacing(10)
grid.addWidget(open_message, 0, 0)
grid.addWidget(self.txt, 1, 0, 1, 2)
grid.addWidget(save, 2, 0)
grid.addWidget(cancel, 2, 1)
self.setFixedSize(self.sizeHint())
def save(self):
value = self.txt.text()
return value
Then you use the exec_() method that returns a code if it is called accept or reject, and according to that the data must be obtained and added. On the other hand, do not use global variables because they are a headache when debugging.
from PyQt4 import QtCore, QtGui
from input_box import Input_Box
class list_form(QtGui.QWidget):
def __init__(self,list_of_items,open_text,parent= None):
super(list_form, self).__init__()
open_message = QtGui.QLabel(open_text)
self.lst = QtGui.QListWidget()
self.lst.addItems([str(i) for i in list_of_items])
add = QtGui.QPushButton('Add', clicked=self.add_button)
grid = QtGui.QGridLayout(self)
grid.setSpacing(10)
grid.addWidget(open_message)
grid.addWidget(self.lst)
grid.addWidget(add)
#QtCore.pyqtSlot()
def add_button(self):
input_box = Input_Box()
input_box.setWindowTitle("Window 2")
if input_box.exec_() == QtGui.QDialog.Accepted:
val = input_box.save()
it = QtGui.QListWidgetItem(val)
self.lst.addItem(it)
self.lst.scrollToItem(it)
if __name__ == "__main__":
import sys
import sip
app = QtGui.QApplication(sys.argv)
window = list_form(list(range(100)),"List of Values")
window.setWindowTitle('Window 1')
window.show()
sip.setdestroyonexit(False)
sys.exit(app.exec_())
The advantage of using QDialog is the decoupling between the classes, for example there is no need to pass a QListWidget as the other answer suggests making it possible that you can use the same dialog for other purposes.
You need to arrange for the action taken when the save button is pressed to pass information back to the list widget. There's more than one way to do it, but just returning the data won't get it done.
Here's an example of the sort of thing that will work - though other approaches are possible.
Change the input_box constructor so it keeps a reference to the list widget which it expects:
class input_box(QtGui.QWidget):
def __init__(self, list_widget, parent= None):
super(input_box, self).__init__()
self.list_widget = list_widget
...
Change the call to the constructor to provide that information:
def add_button(self):
self.input_box = input_box(self.lst)
self.input_box.setWindowTitle("Window 2")
self.input_box.show()
And then use that information in the save method to add to the list widget:
def save(self):
value = self.txt.text()
self.list_widget.addItem(value)
Bingo!
An alternative approach could be to arrange for the input_box to emit a signal with the new value in it, and connect that to a slot on the list_form, or on the list_widget. Or in the input_box you could navigate via its parent to the list_widget. But I think mine is simple and straightforward.
I have a QTabWidget working correctly except that it doesn't re-size how I would expect it.
There are 2 tabs in the widget. Each has a QVBoxLayout with widgets in it. The VBox also works as expected.
The issue is that the first tab has more widgets in its layout than the second tab. When viewing the first tab, the tab sizes to appropriately contain the widgets inside of it. However, when viewing the second tab, the tab widget stays the same size of the first, instead of re-sizing to the visible widgets.
Is this behavior expected? If so, what is a good work around? Id like for the tab widget to always scale to the currently active widget.
EDIT:
Here is an example of the issue. The desired behavior is for Tab B to shrink to its proper size, which can be seen by commenting out the line noted below.
#!/bin/python
import sys
from PySide import QtGui, QtCore
class TabExample(QtGui.QWidget):
def __init__(self):
super(TabExample, self).__init__()
self.initUI()
def initUI(self):
self.vbox_main = QtGui.QVBoxLayout()
self.table_blank = QtGui.QTableWidget(10, 4)
self.tabw = QtGui.QTabWidget()
self.tab_A = QtGui.QWidget()
self.vbox_A = QtGui.QVBoxLayout(self.tab_A)
for i in range(20):
lab = QtGui.QLabel('label %d' %i)
self.vbox_A.addWidget(lab)
self.tab_B = QtGui.QWidget()
self.vbox_B = QtGui.QVBoxLayout(self.tab_B)
for i in range(5):
lab = QtGui.QLabel('labelB %d'%i)
self.vbox_B.addWidget(lab)
#COMMENT OUT NEXT LINE TO SEE DESIRED SIZE OF TAB B
self.tabw.addTab(self.tab_A, 'Tab A')
self.tabw.addTab(self.tab_B, 'Tab B')
self.vbox_main.addWidget(self.table_blank, 1)
self.vbox_main.addWidget(self.tabw)
self.setLayout(self.vbox_main)
self.setGeometry(0,0, 400, 600)
self.move(QtGui.QDesktopWidget().availableGeometry().center() - self.frameGeometry().center())
self.show()
def main():
app = QtGui.QApplication(sys.argv)
tabExample = TabExample()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
This should do the trick; change the size policy depending on which tab is active.
def __init__(self):
super(Widget, self).__init__()
self.setupUi(self)
self.tabWidget_2.currentChanged.connect(self.updateSizes)
def updateSizes(self):
for i in range(self.tabWidget_2.count()):
self.tabWidget_2.widget(i).setSizePolicy(QSizePolicy.Ignored, QSizePolicy.Ignored)
current = self.tabWidget_2.currentWidget()
current.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Minimum)
I have a problem with the creation of multiple tabs in table and a delete button. This button should delete the rows in the current table. My problem is that it only deletes rows in the last created table if I create more than one new tab. And I can't name the tables due to the fact that I don't know how many tabs I need.
import sys
from PyQt4 import QtGui, QtCore
class Fenster(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QMainWindow.__init__(self, parent)
self.resize(300, 300)
addButton = QtGui.QPushButton(u"Add Tab")
self.connect(addButton, QtCore.SIGNAL("clicked()"), self.addTab)
layout = QtGui.QVBoxLayout()
layout.addWidget(addButton)
self.tab_widget = QtGui.QTabWidget()
self.tab_widget.updatesEnabled()
widget = QtGui.QWidget()
self.tab_widget.addTab(widget, "Tab 1")
widget.setLayout(layout)
self.setCentralWidget(self.tab_widget)
self.show()
def addTab(self):
contents = QtGui.QWidget()
delButton = QtGui.QPushButton(u"Del Row")
self.connect(delButton, QtCore.SIGNAL("clicked()"), self.delRow)
self.table = QtGui.QTableWidget(5, 2)
layout = QtGui.QVBoxLayout()
layout.addWidget(self.table)
layout.addWidget(delButton)
self.tab_widget.addTab(contents, "New Tab")
contents.setLayout(layout)
def delRow(self):
self.table.setRowCount(0)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
window = Fenster()
window.show()
sys.exit(app.exec_())
The problem is that self.table always points to the last table widget you created. The delRow method needs to know which table to delete from, so it needs a reference to that table. I would suggest the following code. Here, your slot takes an argument that points to the table you want to delete from.
def addTab(self):
contents = QtGui.QWidget()
table = QtGui.QTableWidget(5, 2)
delButton = QtGui.QPushButton(u"Del Row")
delButton.clicked.connect(lambda: self.delRow(table))
layout = QtGui.QVBoxLayout()
layout.addWidget(table)
layout.addWidget(delButton)
self.tab_widget.addTab(contents, "New Tab")
contents.setLayout(layout)
def delRow(self, table):
table.setRowCount(0)
A couple of things about this code:
I've used the new style signal/slot method to connect the clicked signal to a slot (it is more pythonic)
Because the signal expects to connect to a slot that takes no arguments, I've wrapped your delRow(table) method using lambda. If you haven't come across lambda before, it is basically short hand for writing a one line function. You can read up about it in the Python docs.
You could track which tab is active via currentChanged() signal. Then in signal handler you set self.table.
import sys
from PyQt4 import QtCore, QtGui
class Class1(QtGui.QMainWindow):
def __init__(self):
super(Class1, self).__init__()
self.func()
def func(self):
r0=QtGui.QRadioButton("0",self)
r1=QtGui.QRadioButton("1",self)
ra=QtGui.QRadioButton("a",self)
rb=QtGui.QRadioButton("b",self)
r0.move(100,100)
r1.move(400,100)
ra.move(100,400)
rb.move(400,400)
number_layout=QtGui.QButtonGroup()
letter_layout=QtGui.QButtonGroup()
number_layout.addButton(r0)
number_layout.addButton(r1)
letter_layout.addButton(ra)
letter_layout.addButton(rb)
layout=QtGui.QHBoxLayout(self)
self.show()
def main():
app = QtGui.QApplication(sys.argv)
mw = Class1()
mw.show()
sys.exit(app.exec_())
if __name__=='__main__':
main()
I am trying to group r0,r1 and ra,rb i.e. when r0 is checked, r1 should be unchecked with no effect on states of ra or rb. How can I achieve this? The code indicates what I have tried so far.
A QMainWindow provides a layout already, you can't simply replace that with your own. Either inherit from a plain QWidget, or create a new widget and add the layout and buttons to that.
Your naming is confusing too, QButtonGroup isn't a layout. It doesn't actually provide any visible UI. If you need a UI element that groups buttons, you should look at QGroupBox instead.
Here's a simple variation on what you have above:
def func(self):
layout=QtGui.QHBoxLayout() # layout for the central widget
widget=QtGui.QWidget(self) # central widget
widget.setLayout(layout)
number_group=QtGui.QButtonGroup(widget) # Number group
r0=QtGui.QRadioButton("0")
number_group.addButton(r0)
r1=QtGui.QRadioButton("1")
number_group.addButton(r1)
layout.addWidget(r0)
layout.addWidget(r1)
letter_group=QtGui.QButtonGroup(widget) # Letter group
ra=QtGui.QRadioButton("a")
letter_group.addButton(ra)
rb=QtGui.QRadioButton("b")
letter_group.addButton(rb)
layout.addWidget(ra)
layout.addWidget(rb)
# assign the widget to the main window
self.setCentralWidget(widget)
self.show()
Grouping of radio buttons can be done by all containers. You don't necessarily need QGroupBox, you can use QFrame instead or a QTabWidget. Your choice. Here's a sample code.
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.layoutWidget1 = QtWidgets.QWidget(self.centralwidget)
self.frame_1 = QtWidgets.QFrame(self.layoutWidget1)
self.radio_btn_a = QtWidgets.QRadioButton(self.frame_1)
self.radio_btn_a.setGeometry(QtCore.QRect(160, 80, 40, 17))
self.radio_btn_a.setObjectName("radio_btn_a")
MainWindow.setCentralWidget(self.centralwidget)